-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add d-checkbox component (#146)
* feat: add d-checkbox component * fix: add error text to checkbox * test: checkbox
- Loading branch information
1 parent
3da0f7d
commit aff0b3c
Showing
12 changed files
with
216 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DCheckbox } from './d-checkbox'; | ||
import { Meta, StoryObj } from '@storybook/html'; | ||
|
||
const meta = { | ||
title: 'Design System/DATA DISPLAY/Checkbox', | ||
render: () => | ||
`<d-checkbox> | ||
pippo | ||
</d-checkbox>`, | ||
} satisfies Meta<DCheckbox>; | ||
|
||
export default meta; | ||
type Story = StoryObj<DCheckbox>; | ||
|
||
export const Default: Story = { | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/design/pdwfO3dMKtaCAQakht0JE6/DIDRoom-%2B-Signroom---WF-and-GUI---Dyne.org?node-id=3449-47234&m=dev', | ||
}, | ||
}, | ||
}; |
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 @@ | ||
:host { | ||
display: block; | ||
} |
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,36 @@ | ||
import { Component, EventEmitter, Event, Host, Prop, h } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'd-checkbox', | ||
styleUrl: 'd-checkbox.css', | ||
shadow: true, | ||
}) | ||
export class DCheckbox { | ||
@Prop() checked: boolean; | ||
@Prop() error: string | undefined = undefined; | ||
@Event() dChange!: EventEmitter<boolean>; | ||
|
||
private updateValue = (value: boolean) => { | ||
this.dChange.emit(value); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Host> | ||
<d-vertical-stack> | ||
<d-horizontal-stack> | ||
<ion-checkbox onIonChange={e => this.updateValue(e.detail.checked)} checked={this.checked}></ion-checkbox> | ||
<div> | ||
<slot /> | ||
</div> | ||
</d-horizontal-stack> | ||
{this.error && ( | ||
<d-text size="s" class="text-error"> | ||
{this.error} | ||
</d-text> | ||
)} | ||
</d-vertical-stack> | ||
</Host> | ||
); | ||
} | ||
} |
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,44 @@ | ||
# d-checkbox | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| --------- | --------- | ----------- | --------- | ----------- | | ||
| `checked` | `checked` | | `boolean` | `undefined` | | ||
| `error` | `error` | | `string` | `undefined` | | ||
|
||
|
||
## Events | ||
|
||
| Event | Description | Type | | ||
| --------- | ----------- | ---------------------- | | ||
| `dChange` | | `CustomEvent<boolean>` | | ||
|
||
|
||
## Dependencies | ||
|
||
### Depends on | ||
|
||
- [d-vertical-stack](../vertical-stack) | ||
- [d-horizontal-stack](../horizontal-stack) | ||
- ion-checkbox | ||
- [d-text](../text) | ||
|
||
### Graph | ||
```mermaid | ||
graph TD; | ||
d-checkbox --> d-vertical-stack | ||
d-checkbox --> d-horizontal-stack | ||
d-checkbox --> ion-checkbox | ||
d-checkbox --> d-text | ||
style d-checkbox fill:#f9f,stroke:#333,stroke-width:4px | ||
``` | ||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
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,11 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('d-checkbox', () => { | ||
it('renders', async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent('<d-checkbox></d-checkbox>'); | ||
|
||
const element = await page.find('d-checkbox'); | ||
expect(element).toHaveClass('hydrated'); | ||
}); | ||
}); |
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,25 @@ | ||
import { newSpecPage } from '@stencil/core/testing'; | ||
import { DCheckbox } from '../d-checkbox'; | ||
|
||
describe('d-checkbox', () => { | ||
it('renders', async () => { | ||
const page = await newSpecPage({ | ||
components: [DCheckbox], | ||
html: `<d-checkbox></d-checkbox>`, | ||
}); | ||
expect(page.root).toEqualHtml(` | ||
<d-checkbox> | ||
<mock:shadow-root> | ||
<d-vertical-stack> | ||
<d-horizontal-stack> | ||
<ion-checkbox></ion-checkbox> | ||
<div> | ||
<slot></slot> | ||
</div> | ||
</d-horizontal-stack> | ||
</d-vertical-stack> | ||
</mock:shadow-root> | ||
</d-checkbox> | ||
`); | ||
}); | ||
}); |
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
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