-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checkbox): checkbox element and style for pages refactor
- Loading branch information
1 parent
6c3dd87
commit f45bd25
Showing
12 changed files
with
246 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { registerComponent as registCheckboxComponent } from './elements/checkbox/plugin.js'; | ||
import { registerComponent as registIconComponent } from './elements/icon/plugin.js'; | ||
import { registerComponent as registSwitchComponent } from './elements/switch/plugin.js'; | ||
|
||
registIconComponent(); | ||
registSwitchComponent(); | ||
registCheckboxComponent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
|-------------------------------------------------------------------------- | ||
| Copyright Websublime All Rights Reserved. | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Use of this source code is governed by an MIT-style license that can be | ||
| found in the LICENSE file at https://websublime.dev/license | ||
| | ||
*/ | ||
|
||
import { ComponentMetadata } from '@websublime/vitamin-core'; | ||
import { ComponentElement } from '@websublime/vitamin-core/web-component.js'; | ||
import { css, html, unsafeCSS } from 'lit'; | ||
import { property, query } from 'lit/decorators.js'; | ||
|
||
import { version } from '../../version.js'; | ||
|
||
import style from './style.css'; | ||
import type { CheckboxElementOptions } from './types.js'; | ||
|
||
const metadata: ComponentMetadata = { | ||
description: 'Checkbox component', | ||
link: 'https://websublime.dev/elements/checkbox', | ||
name: 'Checkbox Component', | ||
qa: 'ui-checkbox', | ||
scope: '@websublime/vitamin-ui', | ||
version | ||
}; | ||
|
||
export class CheckboxElement extends ComponentElement<CheckboxElementOptions> { | ||
static styles = css` | ||
${unsafeCSS(style)} | ||
`; | ||
|
||
@property({ reflect: true, type: Boolean }) | ||
checked = false; | ||
|
||
@query('input') | ||
checkbox!: HTMLInputElement; | ||
|
||
constructor() { | ||
super(metadata); | ||
} | ||
|
||
connectedCallback(): void { | ||
super.connectedCallback(); | ||
|
||
const { className = [] } = this.options; | ||
|
||
for (const name of className) { | ||
this.classList.add(name); | ||
} | ||
} | ||
|
||
handleChange() { | ||
this.checked = Boolean(this.checkbox.checked); | ||
|
||
const event = new CustomEvent('change', { bubbles: true, cancelable: true, composed: true, detail: this.checked }); | ||
this.dispatchEvent(event); | ||
} | ||
|
||
render() { | ||
return html` | ||
<label class="ui-checkbox-label" for="checkbox"> | ||
<input type="checkbox" id="checkbox" @change=${this.handleChange} .checked=${this.checked} /> | ||
<slot name="label"></slot> | ||
</label> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'ui-checkbox': CheckboxElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { registerComponent } from './plugin.js'; | ||
export { CheckboxElement } from './checkbox.js'; | ||
export type { CheckboxElementOptions } from './types.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineWebComponent } from '@websublime/vitamin-core/web-component.js'; | ||
|
||
import { CheckboxElement } from './checkbox.js'; | ||
import type { CheckboxElementOptions } from './types.js'; | ||
|
||
/** | ||
* @public | ||
*/ | ||
export const registerComponent = (options: CheckboxElementOptions = {}, name = 'ui-checkbox') => | ||
defineWebComponent(name, CheckboxElement, { | ||
className: ['ui-checkbox'], | ||
enabled: false, | ||
...options | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@tailwind utilities; | ||
@tailwind components; | ||
|
||
@layer components { | ||
:host { | ||
@apply flex flex-wrap content-center; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { WebComponentOptions } from '@websublime/vitamin-core'; | ||
|
||
export interface CheckboxElementOptions extends WebComponentOptions { | ||
className?: string[]; | ||
enabled?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { IconElement, registerComponent as registIconComponent } from './elements/icon/index.js'; | ||
export { SwitchElement, registerComponent as registSwitchComponent } from './elements/switch/index.js'; | ||
export { CheckboxElement, registerComponent as registCheckboxComponent } from './elements/checkbox/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { registerComponent as registCheckboxComponent } from './elements/checkbox/plugin.js'; | ||
import { registerComponent as registIconComponent } from './elements/icon/plugin.js'; | ||
import { registerComponent as registSwitchComponent } from './elements/switch/plugin.js'; | ||
|
||
registIconComponent(); | ||
registSwitchComponent(); | ||
registCheckboxComponent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,51 @@ | ||
@tailwind base; | ||
@tailwind utilities; | ||
@tailwind components; | ||
|
||
.ui-play-section { | ||
display: flex; | ||
@layer base { | ||
body { | ||
--font-size: 16px; | ||
} | ||
} | ||
|
||
@layer utilities { | ||
.transition-colors { | ||
transition-property: color,background-color,border-color,text-decoration-color,fill,stroke; | ||
transition-timing-function: cubic-bezier(.4,0,.2,1); | ||
transition-duration: .15s; | ||
} | ||
|
||
.border-b { | ||
border-bottom-width: 1px; | ||
} | ||
} | ||
|
||
@layer components { | ||
.ui-play-section { | ||
display: flex; | ||
@apply rounded-[0.5rem] border shadow; | ||
} | ||
|
||
.ui-play-container { | ||
flex: 1; | ||
@apply flex-col flex; | ||
} | ||
|
||
.ui-play-nav { | ||
border-bottom-width: 1px; | ||
@apply flex h-16 items-center px-4; | ||
} | ||
|
||
.ui-play-content { | ||
@apply flex-1 space-y-4 p-8 pt-6; | ||
|
||
table tr { | ||
@apply border-b transition-colors; | ||
|
||
td { | ||
@apply p-4 align-middle; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters