Skip to content

Commit

Permalink
feat(button): add button component & demos
Browse files Browse the repository at this point in the history
  • Loading branch information
lingbopro committed Dec 22, 2024
1 parent ffd9a06 commit b8cc852
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default {
'utils',
// component names
// add component name here when adding new component
'button',
'page',
'ripple',
],
Expand Down
28 changes: 28 additions & 0 deletions demos/components/button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Button · Material-Me Component Demo</title>
<link rel="stylesheet" href="../assets/css/index.css" />
<style></style>
<script type="module">
import '../../dist/components/page.js';
import '../../dist/components/button.js';
</script>
</head>
<body>
<mm-page id="root" theme="auto">
<main>
<h1>Button</h1>
<section>
<mm-button> Filled button </mm-button>
<mm-button type="elevated"> Elevated button </mm-button>
<mm-button type="filled-tonal"> Tonal button </mm-button>
<mm-button type="outlined"> Outlined button </mm-button>
<mm-button type="text"> Text button </mm-button>
</section>
</main>
</mm-page>
</body>
</html>
1 change: 1 addition & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<h1>Material-Me Demo</h1>
<section class="links">
<h2>Components</h2>
<mm-ripple><a href="./components/button.html">Button</a></mm-ripple>
<mm-ripple><a href="./components/ripple.html">Ripple</a></mm-ripple>
</section>
<section class="links">
Expand Down
1 change: 1 addition & 0 deletions src/components/button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './button/button';
47 changes: 47 additions & 0 deletions src/components/button/button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
:host {
display: inline-flex;
flex-direction: row;
justify-content: center;
align-items: center;
box-sizing: border-box;
position: relative;
background-color: rgb(var(--mm-color-primary));
color: rgb(var(--mm-color-on-primary));
font-size: 0.875rem;
text-transform: capitalize;
text-overflow: ellipsis;
overflow: hidden;
border-radius: 20px;
padding: 10px 24px;
min-height: 40px;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
--mm-ripple-color: currentColor;
transition: all 0.12s;
}
:host([type='elevated']) {
box-shadow: var(--mm-elevation-level1);
background-color: rgb(var(--mm-color-surface-container-low));
color: rgb(var(--mm-color-primary));
}
:host([type='elevated']:hover) {
box-shadow: var(--mm-elevation-level2);
}
:host([type='filled-tonal']) {
background-color: rgb(var(--mm-color-secondary-container));
color: rgb(var(--mm-color-on-secondary-container));
}
:host([type='filled-tonal']:hover) {
box-shadow: var(--mm-elevation-level1);
}
:host([type='outlined']) {
color: rgb(var(--mm-color-primary));
background-color: initial;
border: solid 1px rgb(var(--mm-color-outline));
}
:host([type='text']) {
color: rgb(var(--mm-color-primary));
background-color: initial;
padding: 10px 14px;
}
2 changes: 2 additions & 0 deletions src/components/button/button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<slot></slot>
<mm-ripple attached></mm-ripple>
23 changes: 23 additions & 0 deletions src/components/button/button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useElement } from '../../core/element';
import '../ripple';
import template from './button.html';
import style from './button.css';

const name = 'mm-button';
const props = {
type: 'filled' as
| 'elevated'
| 'filled'
| 'filled-tonal'
| 'outlined'
| 'text',
};

export class Button extends useElement({
template,
style,
props,
syncProps: ['type'],
}) {}

Button.define(name);
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './button';
export * from './page';
export * from './ripple';

0 comments on commit b8cc852

Please sign in to comment.