revotech-ui-kit 0.0.5-beta → 0.0.7-beta
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.ts +1 -1
- package/dist/rollup-plugin-html-noop.js +1 -0
- package/dist/sw.js +1 -1
- package/dist/sw.js.map +1 -1
- package/package.json +5 -4
- package/.editorconfig +0 -29
- package/.eslintrc +0 -10
- package/.github/workflows/deploy-storybook.yml +0 -107
- package/.storybook/main.ts +0 -17
- package/.storybook/preview-head.html +0 -1
- package/.storybook/preview.ts +0 -17
- package/assets/fonts/Geist/Geist-Black.otf +0 -0
- package/assets/fonts/Geist/Geist-Black.woff2 +0 -0
- package/assets/fonts/Geist/Geist-Bold.otf +0 -0
- package/assets/fonts/Geist/Geist-Bold.woff2 +0 -0
- package/assets/fonts/Geist/Geist-Light.otf +0 -0
- package/assets/fonts/Geist/Geist-Light.woff2 +0 -0
- package/assets/fonts/Geist/Geist-Medium.otf +0 -0
- package/assets/fonts/Geist/Geist-Medium.woff2 +0 -0
- package/assets/fonts/Geist/Geist-Regular.otf +0 -0
- package/assets/fonts/Geist/Geist-Regular.woff2 +0 -0
- package/assets/fonts/Geist/Geist-SemiBold.otf +0 -0
- package/assets/fonts/Geist/Geist-SemiBold.woff2 +0 -0
- package/assets/fonts/Geist/Geist-Thin.otf +0 -0
- package/assets/fonts/Geist/Geist-Thin.woff2 +0 -0
- package/assets/fonts/Geist/Geist-UltraBlack.otf +0 -0
- package/assets/fonts/Geist/Geist-UltraBlack.woff2 +0 -0
- package/assets/fonts/Geist/Geist-UltraLight.otf +0 -0
- package/assets/fonts/Geist/Geist-UltraLight.woff2 +0 -0
- package/assets/fonts/Geist/GeistVariableVF.ttf +0 -0
- package/assets/fonts/Geist/GeistVariableVF.woff2 +0 -0
- package/assets/fonts/Geist/LICENSE.TXT +0 -92
- package/assets/open-wc-logo.svg +0 -29
- package/assume_role.sh +0 -18
- package/index.html +0 -314
- package/rollup.config.js +0 -83
- package/src/assets/icons/arrows.icon.ts +0 -20
- package/src/assets/icons/index.ts +0 -3
- package/src/assets/icons/search.icon.ts +0 -19
- package/src/assets/icons/tick.icon.ts +0 -20
- package/src/chai-custom.d.ts +0 -0
- package/src/components/atoms/alert/alert-description.ts +0 -15
- package/src/components/atoms/alert/alert-title.ts +0 -17
- package/src/components/atoms/alert/alert.atom.ts +0 -55
- package/src/components/atoms/alert/alert.stories.ts +0 -71
- package/src/components/atoms/alert/alert.styles.ts +0 -21
- package/src/components/atoms/alert/alert.types.ts +0 -1
- package/src/components/atoms/badge/badge.atom.ts +0 -40
- package/src/components/atoms/badge/badge.stories.ts +0 -118
- package/src/components/atoms/badge/badge.style.ts +0 -24
- package/src/components/atoms/badge/badge.type.ts +0 -7
- package/src/components/atoms/button/button.atom.ts +0 -59
- package/src/components/atoms/button/button.stories.ts +0 -224
- package/src/components/atoms/button/button.style.ts +0 -31
- package/src/components/atoms/button/button.type.ts +0 -10
- package/src/components/atoms/card/card-content.ts +0 -15
- package/src/components/atoms/card/card-description.ts +0 -15
- package/src/components/atoms/card/card-footer.ts +0 -15
- package/src/components/atoms/card/card-header.ts +0 -15
- package/src/components/atoms/card/card-title.ts +0 -15
- package/src/components/atoms/card/card.atom.ts +0 -31
- package/src/components/atoms/card/card.stories.ts +0 -149
- package/src/components/atoms/checkbox/checkbox.atom.ts +0 -76
- package/src/components/atoms/checkbox/checkbox.stories.ts +0 -309
- package/src/components/atoms/checkbox/checkbox.style.ts +0 -5
- package/src/components/atoms/checkbox/checkbox.type.ts +0 -24
- package/src/components/atoms/combo-box/combo-box-input.ts +0 -33
- package/src/components/atoms/combo-box/combo-box-item.ts +0 -59
- package/src/components/atoms/combo-box/combo-box-list.ts +0 -57
- package/src/components/atoms/combo-box/combo-box.atom.ts +0 -187
- package/src/components/atoms/combo-box/combo-box.stories.ts +0 -95
- package/src/components/atoms/command-empty/command-empty.atom.ts +0 -44
- package/src/components/atoms/command-group/command-group.atom.ts +0 -60
- package/src/components/atoms/command-item/command-item.atom.ts +0 -74
- package/src/components/atoms/command-list/command-list.atom.ts +0 -37
- package/src/components/atoms/command-separator/command-separator.atom.ts +0 -42
- package/src/components/atoms/dialog/dialog-close.ts +0 -50
- package/src/components/atoms/dialog/dialog-content.ts +0 -71
- package/src/components/atoms/dialog/dialog-footer.ts +0 -22
- package/src/components/atoms/dialog/dialog-header.ts +0 -36
- package/src/components/atoms/dialog/dialog-overly.ts +0 -20
- package/src/components/atoms/dialog/dialog-trigger.ts +0 -54
- package/src/components/atoms/dialog/dialog.atom.ts +0 -78
- package/src/components/atoms/dialog/dialog.stories.ts +0 -93
- package/src/components/atoms/dropdownMenu/dropdown-menu-checkbox-Item.ts +0 -106
- package/src/components/atoms/dropdownMenu/dropdown-menu-content.ts +0 -79
- package/src/components/atoms/dropdownMenu/dropdown-menu-group.ts +0 -60
- package/src/components/atoms/dropdownMenu/dropdown-menu-item.ts +0 -74
- package/src/components/atoms/dropdownMenu/dropdown-menu-radio-item.ts +0 -107
- package/src/components/atoms/dropdownMenu/dropdown-menu-seperator.ts +0 -44
- package/src/components/atoms/dropdownMenu/dropdown-menu-shortcut.ts +0 -17
- package/src/components/atoms/dropdownMenu/dropdown-menu.atom.ts +0 -84
- package/src/components/atoms/dropdownMenu/dropdownMenu.stories.ts +0 -220
- package/src/components/atoms/dropdownMenu/dropdownMenu.style.ts +0 -7
- package/src/components/atoms/index.ts +0 -13
- package/src/components/atoms/input/input.atom.ts +0 -88
- package/src/components/atoms/input/input.stories.ts +0 -451
- package/src/components/atoms/input/input.styles.ts +0 -2
- package/src/components/atoms/input/input.type.ts +0 -58
- package/src/components/atoms/label/label.atom.ts +0 -64
- package/src/components/atoms/label/label.stories.ts +0 -102
- package/src/components/atoms/label/label.style.ts +0 -5
- package/src/components/atoms/popover/popover-content.ts +0 -58
- package/src/components/atoms/popover/popover-trigger.ts +0 -50
- package/src/components/atoms/popover/popover.atom.ts +0 -34
- package/src/components/atoms/popover/popover.stories.ts +0 -79
- package/src/components/atoms/popover/popover.style.ts +0 -25
- package/src/components/atoms/popover/popover.types.ts +0 -3
- package/src/components/atoms/toggle/defs.ts +0 -29
- package/src/components/atoms/toggle/toggle.atom.ts +0 -58
- package/src/components/atoms/toggle/toggle.stories.ts +0 -204
- package/src/components/atoms/toggle/toggle.style.ts +0 -22
- package/src/components/command/command.stories.ts +0 -154
- package/src/components/command/command.ts +0 -391
- package/src/components/index.ts +0 -2
- package/src/components/molecules/command/command.molecules.ts +0 -31
- package/src/components/molecules/command-input/command-input.atom.ts +0 -130
- package/src/components/molecules/dropdownMenu/dropdownMenu.molecules.ts +0 -0
- package/src/components/molecules/index.ts +0 -1
- package/src/globals.css +0 -2215
- package/src/helpers/base-element.ts +0 -79
- package/src/helpers/index.ts +0 -3
- package/src/helpers/mouse-conroller.helper.ts +0 -42
- package/src/helpers/style.helpers.ts +0 -6
- package/src/index.d.ts +0 -1
- package/src/index.ts +0 -1
- package/src/interfaces/actionable.interface.ts +0 -6
- package/src/interfaces/atomic.interface.ts +0 -6
- package/src/interfaces/changeable.interface.ts +0 -14
- package/src/interfaces/child-support-atomic.interface.ts +0 -5
- package/src/interfaces/index.ts +0 -6
- package/src/interfaces/intractable.interface.ts +0 -6
- package/src/interfaces/variant.interface.ts +0 -3
- package/src/lib/index.ts +0 -0
- package/src/lib/next/next.lib.ts +0 -0
- package/src/lib/react/react.lib.ts +0 -18
- package/src/lib/tw-styles.ts +0 -1957
- package/src/styles/index.ts +0 -1
- package/src/styles/tw.styles.ts +0 -2219
- package/src/tailwind-lib.css +0 -115
- package/src/wc-ui-app.ts +0 -81
- package/tailwind.config.js +0 -217
- package/test/wc-ui-app.test.ts +0 -22
- package/tsconfig.json +0 -30
- package/web-dev-server.config.mjs +0 -26
- package/web-test-runner.config.mjs +0 -41
@@ -1,149 +0,0 @@
|
|
1
|
-
import { html } from 'lit';
|
2
|
-
import type { Meta, StoryFn, StoryObj } from '@storybook/web-components';
|
3
|
-
import { expect, within, fn, waitFor, userEvent } from '@storybook/test';
|
4
|
-
import './card.atom';
|
5
|
-
|
6
|
-
export default {
|
7
|
-
component: 'components/card',
|
8
|
-
tags: ['autodocs'],
|
9
|
-
} as Meta;
|
10
|
-
|
11
|
-
type Story = StoryObj;
|
12
|
-
|
13
|
-
const testCardBehavior = async (args: any, canvasElement: HTMLElement) => {
|
14
|
-
const canvas = within(canvasElement);
|
15
|
-
const card = await waitFor(() => canvas.getByTestId('card-id'));
|
16
|
-
const cardHeader = await waitFor(() => canvas.getByTestId('card-header-id'));
|
17
|
-
const cardTitle = await waitFor(() => canvas.getByTestId('card-title-id'));
|
18
|
-
const cardDescription = await waitFor(() =>
|
19
|
-
canvas.getByTestId('card-description-id')
|
20
|
-
);
|
21
|
-
const cardContent = await waitFor(() =>
|
22
|
-
canvas.getByTestId('card-content-id')
|
23
|
-
);
|
24
|
-
const cardFooter = await waitFor(() => canvas.getByTestId('card-footer-id'));
|
25
|
-
expect(card).toBeVisible();
|
26
|
-
expect(cardHeader).toBeVisible();
|
27
|
-
expect(cardTitle).toBeVisible();
|
28
|
-
expect(cardDescription).toBeVisible();
|
29
|
-
expect(cardContent).toBeVisible();
|
30
|
-
expect(cardFooter).toBeVisible();
|
31
|
-
|
32
|
-
if (card.shadowRoot) {
|
33
|
-
const cardItem = await card.shadowRoot.getElementById('rtg-card-id');
|
34
|
-
expect(cardItem).toHaveClass(
|
35
|
-
'rounded-lg border bg-card text-card-foreground shadow-sm p-6'
|
36
|
-
);
|
37
|
-
}
|
38
|
-
if (cardTitle) {
|
39
|
-
expect(cardTitle.textContent).toContain('Create project');
|
40
|
-
expect(cardTitle.tagName.toLowerCase()).toEqual('cardtitle');
|
41
|
-
}
|
42
|
-
if (cardDescription) {
|
43
|
-
expect(cardDescription.textContent).toContain(
|
44
|
-
'Deploy your new project in one-click.'
|
45
|
-
);
|
46
|
-
expect(cardDescription.tagName.toLowerCase()).toEqual('carddescription');
|
47
|
-
}
|
48
|
-
};
|
49
|
-
|
50
|
-
export const Cards: Story = {
|
51
|
-
name: 'Cards',
|
52
|
-
render: () => html`
|
53
|
-
<rtg-card data-testid="card-id">
|
54
|
-
<CardHeader data-testid="card-header-id">
|
55
|
-
<CardTitle data-testid="card-title-id">
|
56
|
-
<h3>Create project</h3>
|
57
|
-
</CardTitle>
|
58
|
-
<CardDescription data-testid="card-description-id">
|
59
|
-
<p class="text-sm text-muted-foreground">
|
60
|
-
Deploy your new project in one-click.
|
61
|
-
</p>
|
62
|
-
</CardDescription>
|
63
|
-
</CardHeader>
|
64
|
-
<CardContent data-testid="card-content-id">
|
65
|
-
<form class="pt-4">
|
66
|
-
<div class="grid w-full items-center gap-4">
|
67
|
-
<div class="flex flex-col space-y-1.5">
|
68
|
-
<label
|
69
|
-
class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
70
|
-
for="name"
|
71
|
-
>Name</label
|
72
|
-
><input
|
73
|
-
class="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
74
|
-
id="name"
|
75
|
-
placeholder="Name of your project"
|
76
|
-
/>
|
77
|
-
</div>
|
78
|
-
<div class="flex flex-col space-y-1.5">
|
79
|
-
<label
|
80
|
-
class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
81
|
-
for="framework"
|
82
|
-
>Framework</label
|
83
|
-
><button
|
84
|
-
type="button"
|
85
|
-
role="combobox"
|
86
|
-
aria-controls="radix-:r2b:"
|
87
|
-
aria-expanded="false"
|
88
|
-
aria-autocomplete="none"
|
89
|
-
dir="ltr"
|
90
|
-
data-state="closed"
|
91
|
-
data-placeholder=""
|
92
|
-
class="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1"
|
93
|
-
id="framework"
|
94
|
-
>
|
95
|
-
<span style="pointer-events: none;">Select</span
|
96
|
-
><svg
|
97
|
-
xmlns="http://www.w3.org/2000/svg"
|
98
|
-
width="24"
|
99
|
-
height="24"
|
100
|
-
viewBox="0 0 24 24"
|
101
|
-
fill="none"
|
102
|
-
stroke="currentColor"
|
103
|
-
stroke-width="2"
|
104
|
-
stroke-linecap="round"
|
105
|
-
stroke-linejoin="round"
|
106
|
-
class="lucide lucide-chevron-down h-4 w-4 opacity-50"
|
107
|
-
aria-hidden="true"
|
108
|
-
>
|
109
|
-
<path d="m6 9 6 6 6-6"></path>
|
110
|
-
</svg></button
|
111
|
-
><select
|
112
|
-
aria-hidden="true"
|
113
|
-
tabindex="-1"
|
114
|
-
style="position: absolute; border: 0px; width: 1px; height: 1px; padding: 0px; margin: -1px; overflow: hidden; clip: rect(0px, 0px, 0px, 0px); white-space: nowrap; overflow-wrap: normal;"
|
115
|
-
>
|
116
|
-
<option value=""></option>
|
117
|
-
<option value="next">Next.js</option>
|
118
|
-
<option value="sveltekit">SvelteKit</option>
|
119
|
-
<option value="astro">Astro</option>
|
120
|
-
<option value="nuxt">Nuxt.js</option>
|
121
|
-
</select>
|
122
|
-
</div>
|
123
|
-
</div>
|
124
|
-
</form>
|
125
|
-
</CardContent>
|
126
|
-
<CardFooter data-testid="card-footer-id">
|
127
|
-
<div class="items-center pt-4 flex justify-between">
|
128
|
-
<button
|
129
|
-
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2"
|
130
|
-
>
|
131
|
-
Cancel
|
132
|
-
</button>
|
133
|
-
<button
|
134
|
-
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2"
|
135
|
-
>
|
136
|
-
Deploy
|
137
|
-
</button>
|
138
|
-
</div>
|
139
|
-
</CardFooter>
|
140
|
-
</rtg-card>
|
141
|
-
`,
|
142
|
-
play: async ({ args, canvasElement }) => {
|
143
|
-
try {
|
144
|
-
await testCardBehavior(args, canvasElement);
|
145
|
-
} catch (error) {
|
146
|
-
console.error('An error occurred during the play function:', error);
|
147
|
-
}
|
148
|
-
},
|
149
|
-
};
|
@@ -1,76 +0,0 @@
|
|
1
|
-
import { LitElement, html, css, nothing } from 'lit';
|
2
|
-
import { property, customElement } from 'lit/decorators.js';
|
3
|
-
import { cn } from '../../../helpers';
|
4
|
-
import { TWStyles } from '../../../styles';
|
5
|
-
import { checkboxStyles, iconStyles } from './checkbox.style';
|
6
|
-
import { CheckboxProperties } from './checkbox.type';
|
7
|
-
|
8
|
-
@customElement('rtg-checkbox')
|
9
|
-
export class Checkbox extends LitElement implements CheckboxProperties {
|
10
|
-
@property({ type: Boolean }) disabled = false;
|
11
|
-
|
12
|
-
@property({ type: Boolean }) checked = false;
|
13
|
-
|
14
|
-
@property({ type: String }) type = 'text';
|
15
|
-
|
16
|
-
@property({ type: String }) value = '';
|
17
|
-
|
18
|
-
@property({ type: Boolean }) required = false;
|
19
|
-
|
20
|
-
static styles = [css``, TWStyles];
|
21
|
-
|
22
|
-
private _onClick(e: Event) {
|
23
|
-
if (e.defaultPrevented) return;
|
24
|
-
this.checked = !this.checked;
|
25
|
-
this.required = !this.required;
|
26
|
-
|
27
|
-
// Dispatch a custom change event when the state changes
|
28
|
-
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
29
|
-
}
|
30
|
-
|
31
|
-
public click() {
|
32
|
-
this.checked = !this.checked;
|
33
|
-
this.required = !this.required;
|
34
|
-
}
|
35
|
-
|
36
|
-
render() {
|
37
|
-
const additionalProps = { ...this.dataset }; // Example of additional props
|
38
|
-
return html`
|
39
|
-
<button
|
40
|
-
data-testid="checkbox-atom"
|
41
|
-
type="button"
|
42
|
-
role="checkbox"
|
43
|
-
aria-checked="${this.checked || this.value === 'on'}"
|
44
|
-
data-state="${this.checked || this.value === 'on'
|
45
|
-
? 'checked'
|
46
|
-
: 'unchecked'}"
|
47
|
-
value="${this.value}"
|
48
|
-
?required=${this.required}
|
49
|
-
?disabled=${this.disabled}
|
50
|
-
@click="${this._onClick}"
|
51
|
-
class="${cn(checkboxStyles, this.className)}"
|
52
|
-
${Object.entries(additionalProps).map(
|
53
|
-
([key, value]) => html` ${key}="${value}" `
|
54
|
-
)}
|
55
|
-
>
|
56
|
-
${this.checked || this.value === 'on'
|
57
|
-
? html`<span data-state="checked" class="${iconStyles}"
|
58
|
-
><svg
|
59
|
-
xmlns="http://www.w3.org/2000/svg"
|
60
|
-
width="24"
|
61
|
-
height="24"
|
62
|
-
viewBox="0 0 24 24"
|
63
|
-
fill="none"
|
64
|
-
stroke="currentColor"
|
65
|
-
stroke-width="3"
|
66
|
-
stroke-linecap="round"
|
67
|
-
stroke-linejoin="round"
|
68
|
-
class="h-4 w-4"
|
69
|
-
>
|
70
|
-
<polyline points="20 6 9 17 4 12"></polyline></svg
|
71
|
-
></span>`
|
72
|
-
: nothing}
|
73
|
-
</button>
|
74
|
-
`;
|
75
|
-
}
|
76
|
-
}
|
@@ -1,309 +0,0 @@
|
|
1
|
-
import type { Meta, StoryFn, StoryContext } from '@storybook/web-components';
|
2
|
-
import { html } from 'lit';
|
3
|
-
import './checkbox.atom';
|
4
|
-
import { expect, within, userEvent, waitFor, fn } from '@storybook/test';
|
5
|
-
import {
|
6
|
-
CheckboxArgs,
|
7
|
-
CheckboxWithRequiredArgs,
|
8
|
-
CheckboxWithValueArgs,
|
9
|
-
} from './checkbox.type';
|
10
|
-
import '../button/button.atom';
|
11
|
-
|
12
|
-
const allowedTypes = ['checkbox'];
|
13
|
-
|
14
|
-
export default {
|
15
|
-
component: 'components/checkbox',
|
16
|
-
tags: ['autodocs'],
|
17
|
-
} as Meta;
|
18
|
-
|
19
|
-
const mockOnClickHandler = fn(event => {
|
20
|
-
alert('submit data!');
|
21
|
-
});
|
22
|
-
|
23
|
-
const testCheckboxBehavior = async (
|
24
|
-
args: CheckboxArgs,
|
25
|
-
canvasElement: HTMLElement
|
26
|
-
) => {
|
27
|
-
const canvas = within(canvasElement);
|
28
|
-
const checkbox = await waitFor(() => canvas.getByTestId('checkbox-id'));
|
29
|
-
|
30
|
-
if (checkbox.shadowRoot) {
|
31
|
-
const innerCheckbox = checkbox.shadowRoot.querySelector(
|
32
|
-
'[data-testid="checkbox-atom"]'
|
33
|
-
);
|
34
|
-
|
35
|
-
// 1. Test: Checkbox should have correct Role attribute
|
36
|
-
expect(innerCheckbox).toHaveRole('checkbox');
|
37
|
-
|
38
|
-
// 2. Test: Checkbox should have the correct `checked` state based on args
|
39
|
-
if (args.checked) {
|
40
|
-
expect(innerCheckbox).toBeChecked();
|
41
|
-
} else {
|
42
|
-
expect(innerCheckbox).not.toBeChecked();
|
43
|
-
}
|
44
|
-
|
45
|
-
// 3. Test: Checkbox should be disabled when the `disabled` prop is true
|
46
|
-
if (args.disabled) {
|
47
|
-
expect(innerCheckbox).toBeDisabled();
|
48
|
-
} else {
|
49
|
-
expect(innerCheckbox).not.toBeDisabled();
|
50
|
-
}
|
51
|
-
|
52
|
-
// 4. Test: Label should have correct `for` attribute linking to the checkbox
|
53
|
-
const label = await waitFor(() => canvas.getByText(args.label));
|
54
|
-
expect(label).toBeInTheDocument();
|
55
|
-
expect(label).toHaveAttribute('for', checkbox.getAttribute('id'));
|
56
|
-
}
|
57
|
-
};
|
58
|
-
|
59
|
-
const testCheckboxWithRequiredBehavior = async (
|
60
|
-
args: CheckboxWithRequiredArgs,
|
61
|
-
canvasElement: HTMLElement
|
62
|
-
) => {
|
63
|
-
const canvas = within(canvasElement);
|
64
|
-
const checkbox = await waitFor(() => canvas.getByTestId('checkbox-id'));
|
65
|
-
const button = await waitFor(() => canvas.getByTestId('btn-id'));
|
66
|
-
|
67
|
-
if (checkbox.shadowRoot) {
|
68
|
-
const innerCheckbox = checkbox.shadowRoot.querySelector(
|
69
|
-
'[data-testid="checkbox-atom"]'
|
70
|
-
);
|
71
|
-
|
72
|
-
// Test: Checkbox should have the correct required attribute
|
73
|
-
if (args.required) {
|
74
|
-
expect(innerCheckbox).toHaveAttribute('required');
|
75
|
-
} else {
|
76
|
-
expect(innerCheckbox).not.toHaveAttribute('required');
|
77
|
-
}
|
78
|
-
|
79
|
-
// Test: Button should be disabled when checkbox is unchecked and required is true
|
80
|
-
if (args.required && !args.checked) {
|
81
|
-
expect(button).toBeDisabled();
|
82
|
-
} else if (args.required && args.checked) {
|
83
|
-
expect(button).not.toBeDisabled();
|
84
|
-
}
|
85
|
-
|
86
|
-
// Additional tests for the checked state
|
87
|
-
if (args.checked) {
|
88
|
-
expect(innerCheckbox).toBeChecked();
|
89
|
-
} else {
|
90
|
-
expect(innerCheckbox).not.toBeChecked();
|
91
|
-
}
|
92
|
-
|
93
|
-
// Additional tests for the disabled state
|
94
|
-
if (args.disabled) {
|
95
|
-
expect(innerCheckbox).toBeDisabled();
|
96
|
-
} else {
|
97
|
-
expect(innerCheckbox).not.toBeDisabled();
|
98
|
-
}
|
99
|
-
}
|
100
|
-
};
|
101
|
-
|
102
|
-
const testCheckboxWithValueBehavior = async (
|
103
|
-
args: CheckboxWithValueArgs,
|
104
|
-
canvasElement: HTMLElement
|
105
|
-
) => {
|
106
|
-
const canvas = within(canvasElement);
|
107
|
-
const checkbox = await waitFor(() => canvas.getByTestId('checkbox-id'));
|
108
|
-
|
109
|
-
if (checkbox.shadowRoot) {
|
110
|
-
const innerCheckbox = checkbox.shadowRoot.querySelector(
|
111
|
-
'[data-testid="checkbox-atom"]'
|
112
|
-
);
|
113
|
-
|
114
|
-
// Test: Checkbox should have the correct value attribute
|
115
|
-
expect(innerCheckbox).toHaveAttribute('value', args.value);
|
116
|
-
|
117
|
-
// Additional tests for disabled state if needed
|
118
|
-
if (args.disabled) {
|
119
|
-
expect(innerCheckbox).toBeDisabled();
|
120
|
-
} else {
|
121
|
-
expect(innerCheckbox).not.toBeDisabled();
|
122
|
-
}
|
123
|
-
}
|
124
|
-
};
|
125
|
-
|
126
|
-
const TemplatewithChecked: StoryFn = ({ disabled, checked, label }) =>
|
127
|
-
html`
|
128
|
-
<div style="display:flex">
|
129
|
-
<rtg-checkbox
|
130
|
-
id="terms"
|
131
|
-
data-testid="checkbox-id"
|
132
|
-
?disabled=${disabled}
|
133
|
-
?checked=${checked}
|
134
|
-
></rtg-checkbox>
|
135
|
-
<rtg-label style="margin:2px 0px 0px 4px" for="terms">${label}</rtg-label>
|
136
|
-
</div>
|
137
|
-
`;
|
138
|
-
|
139
|
-
const TemplatewithRequired: StoryFn = ({
|
140
|
-
disabled,
|
141
|
-
checked,
|
142
|
-
label,
|
143
|
-
required,
|
144
|
-
}) =>
|
145
|
-
html`
|
146
|
-
<div style="display: flex; flex-direction: column;">
|
147
|
-
<div style="display:flex">
|
148
|
-
<rtg-checkbox
|
149
|
-
id="terms"
|
150
|
-
data-testid="checkbox-id"
|
151
|
-
?disabled=${disabled}
|
152
|
-
?checked=${checked}
|
153
|
-
?required=${required}
|
154
|
-
@click=${(e: Event) => {
|
155
|
-
const checkbox = e.target as HTMLInputElement;
|
156
|
-
const button = document.querySelector(
|
157
|
-
'rtg-button'
|
158
|
-
) as HTMLButtonElement;
|
159
|
-
if (button) {
|
160
|
-
button.disabled = required ? !checkbox.checked : false;
|
161
|
-
}
|
162
|
-
}}
|
163
|
-
></rtg-checkbox>
|
164
|
-
<rtg-label style="margin:2px 0px 0px 4px" for="terms"
|
165
|
-
>${label}</rtg-label
|
166
|
-
>
|
167
|
-
</div>
|
168
|
-
<div style="margin-top:16px">
|
169
|
-
<rtg-button
|
170
|
-
variant="default"
|
171
|
-
size="default"
|
172
|
-
data-testid="btn-id"
|
173
|
-
?disabled=${required ? !checked : false}
|
174
|
-
.click=${mockOnClickHandler}
|
175
|
-
>Submit</rtg-button
|
176
|
-
>
|
177
|
-
</div>
|
178
|
-
</div>
|
179
|
-
`;
|
180
|
-
|
181
|
-
const TemplateWithVlaue: StoryFn = ({ disabled, label, value }) =>
|
182
|
-
html`
|
183
|
-
<div style="display:flex">
|
184
|
-
<rtg-checkbox
|
185
|
-
id="terms"
|
186
|
-
data-testid="checkbox-id"
|
187
|
-
value=${value}
|
188
|
-
?disabled=${disabled}
|
189
|
-
></rtg-checkbox>
|
190
|
-
<rtg-label style="margin:2px 0px 0px 4px" for="terms">${label}</rtg-label>
|
191
|
-
</div>
|
192
|
-
`;
|
193
|
-
|
194
|
-
export const CheckboxWithReuired = TemplatewithRequired.bind({});
|
195
|
-
CheckboxWithReuired.args = {
|
196
|
-
disabled: false,
|
197
|
-
checked: false,
|
198
|
-
required: false,
|
199
|
-
label: 'Accept terms and conditions',
|
200
|
-
};
|
201
|
-
|
202
|
-
CheckboxWithReuired.parameters = {
|
203
|
-
docs: {
|
204
|
-
source: {
|
205
|
-
transform: (code: string, storyContext: StoryContext) => {
|
206
|
-
const args = storyContext.args;
|
207
|
-
|
208
|
-
// Handling boolean attributes: if true, render without value, if false, omit the attribute
|
209
|
-
const updatedCode = code
|
210
|
-
.replace(/disabled=""/g, 'disabled=true')
|
211
|
-
.replace(/checked=""/g, 'checked=true')
|
212
|
-
.replace(/required=""/g, 'required=true')
|
213
|
-
.replace(/disabled="false"/g, '')
|
214
|
-
.replace(/checked="false"/g, '')
|
215
|
-
.replace(/required="false"/g, '');
|
216
|
-
|
217
|
-
return updatedCode;
|
218
|
-
},
|
219
|
-
},
|
220
|
-
},
|
221
|
-
};
|
222
|
-
|
223
|
-
CheckboxWithReuired.argTypes = {
|
224
|
-
disabled: {
|
225
|
-
control: 'boolean',
|
226
|
-
description: 'Determines whether the checkbox is disabled (unclickable).',
|
227
|
-
table: {
|
228
|
-
defaultValue: { summary: 'false' },
|
229
|
-
},
|
230
|
-
docs: {
|
231
|
-
source: {
|
232
|
-
code: (args: { disabled: boolean }) => (args.disabled ? true : ''),
|
233
|
-
},
|
234
|
-
},
|
235
|
-
},
|
236
|
-
checked: {
|
237
|
-
control: 'boolean',
|
238
|
-
description: 'Specifies whether the checkbox is checked by default.',
|
239
|
-
table: {
|
240
|
-
defaultValue: { summary: 'false' },
|
241
|
-
},
|
242
|
-
},
|
243
|
-
required: {
|
244
|
-
control: 'boolean',
|
245
|
-
description:
|
246
|
-
'Marks the checkbox as a required field. When true, the checkbox must be checked for form submission, and related actions such as enabling a submit button are dependent on this state.',
|
247
|
-
table: {
|
248
|
-
defaultValue: { summary: 'false' },
|
249
|
-
},
|
250
|
-
},
|
251
|
-
label: {
|
252
|
-
control: 'text',
|
253
|
-
description:
|
254
|
-
'The text displayed next to the checkbox, describing its purpose.',
|
255
|
-
},
|
256
|
-
};
|
257
|
-
|
258
|
-
CheckboxWithReuired.play = async ({ args, canvasElement }) => {
|
259
|
-
await testCheckboxWithRequiredBehavior(
|
260
|
-
args as CheckboxWithRequiredArgs,
|
261
|
-
canvasElement
|
262
|
-
);
|
263
|
-
};
|
264
|
-
|
265
|
-
export const Checkbox = TemplatewithChecked.bind({});
|
266
|
-
Checkbox.args = {
|
267
|
-
disabled: false,
|
268
|
-
checked: false,
|
269
|
-
label: 'Accept terms and conditions',
|
270
|
-
};
|
271
|
-
|
272
|
-
Checkbox.argTypes = {
|
273
|
-
disabled: {
|
274
|
-
control: 'boolean',
|
275
|
-
},
|
276
|
-
checked: {
|
277
|
-
control: 'boolean',
|
278
|
-
},
|
279
|
-
label: {
|
280
|
-
control: 'text',
|
281
|
-
},
|
282
|
-
};
|
283
|
-
|
284
|
-
Checkbox.play = async ({ args, canvasElement }) => {
|
285
|
-
await testCheckboxBehavior(args as CheckboxArgs, canvasElement);
|
286
|
-
};
|
287
|
-
|
288
|
-
export const CheckboxWithValue = TemplateWithVlaue.bind({});
|
289
|
-
CheckboxWithValue.args = {
|
290
|
-
disabled: false,
|
291
|
-
value: 'off',
|
292
|
-
label: 'Accept terms and conditions',
|
293
|
-
};
|
294
|
-
|
295
|
-
CheckboxWithValue.argTypes = {
|
296
|
-
disabled: { control: 'boolean' },
|
297
|
-
value: {
|
298
|
-
control: { type: 'select' },
|
299
|
-
options: ['on', 'off'],
|
300
|
-
},
|
301
|
-
label: { control: 'text' },
|
302
|
-
};
|
303
|
-
|
304
|
-
CheckboxWithValue.play = async ({ args, canvasElement }) => {
|
305
|
-
await testCheckboxWithValueBehavior(
|
306
|
-
args as CheckboxWithValueArgs,
|
307
|
-
canvasElement
|
308
|
-
);
|
309
|
-
};
|
@@ -1,5 +0,0 @@
|
|
1
|
-
export const checkboxStyles =
|
2
|
-
'peer h-4 w-4 align-middle shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground';
|
3
|
-
|
4
|
-
export const iconStyles =
|
5
|
-
'flex items-center justify-center text-current pointer-events-none';
|
@@ -1,24 +0,0 @@
|
|
1
|
-
export type CheckboxProperties = {
|
2
|
-
disabled: boolean;
|
3
|
-
checked: boolean;
|
4
|
-
};
|
5
|
-
|
6
|
-
export type CheckboxArgs = {
|
7
|
-
disabled: boolean;
|
8
|
-
checked: boolean;
|
9
|
-
label: string;
|
10
|
-
};
|
11
|
-
|
12
|
-
export type CheckboxWithRequiredArgs = {
|
13
|
-
disabled: boolean;
|
14
|
-
checked: boolean;
|
15
|
-
required: boolean;
|
16
|
-
label: string;
|
17
|
-
value?: string;
|
18
|
-
};
|
19
|
-
|
20
|
-
export type CheckboxWithValueArgs = {
|
21
|
-
disabled: boolean;
|
22
|
-
value: string;
|
23
|
-
label: string;
|
24
|
-
};
|
@@ -1,33 +0,0 @@
|
|
1
|
-
import { LitElement, html, css } from 'lit';
|
2
|
-
import { customElement, property } from 'lit/decorators.js';
|
3
|
-
import { TWStyles } from '../../../styles';
|
4
|
-
|
5
|
-
@customElement('combo-box-input')
|
6
|
-
export class ComboBoxInput extends LitElement {
|
7
|
-
@property({ type: String }) value = '';
|
8
|
-
@property({ type: Function }) handleClick = () => {};
|
9
|
-
@property({ type: Function }) handleKeyDown = () => {};
|
10
|
-
|
11
|
-
static styles = [css``, TWStyles];
|
12
|
-
|
13
|
-
render() {
|
14
|
-
return html`
|
15
|
-
<input
|
16
|
-
class="inline-flex justify-between items-center w-full h-10 px-4 py-2 whitespace-nowrap rounded-md
|
17
|
-
text-sm font-medium border border-input cursor-pointer
|
18
|
-
ring-offset-background
|
19
|
-
transition-colors disabled:pointer-events-none
|
20
|
-
disabled:opacity-50
|
21
|
-
bg-background hover:bg-accent
|
22
|
-
hover:text-accent-foreground
|
23
|
-
outline-none"
|
24
|
-
role="combobox"
|
25
|
-
aria-expanded="false"
|
26
|
-
readonly="true"
|
27
|
-
.value=${this.value}
|
28
|
-
@click=${this.handleClick}
|
29
|
-
@keydown=${this.handleKeyDown}
|
30
|
-
/>
|
31
|
-
`;
|
32
|
-
}
|
33
|
-
}
|
@@ -1,59 +0,0 @@
|
|
1
|
-
import { LitElement, css, html } from 'lit';
|
2
|
-
import { customElement, property } from 'lit/decorators.js';
|
3
|
-
import { tickIcon } from '../../../assets/icons';
|
4
|
-
import { TWStyles } from '../../../styles';
|
5
|
-
|
6
|
-
@customElement('combo-box-item')
|
7
|
-
export class ComboBoxItem extends LitElement {
|
8
|
-
@property({ type: String }) key = '';
|
9
|
-
@property({ type: String }) searchText = '';
|
10
|
-
@property({ type: String }) value = '';
|
11
|
-
@property({ type: Number }) tabindex = 0;
|
12
|
-
@property({ type: Boolean }) isSelected = false;
|
13
|
-
@property({ type: String }) class = '';
|
14
|
-
@property({ type: Function }) onSelect = () => {};
|
15
|
-
|
16
|
-
static styles = [css``, TWStyles];
|
17
|
-
|
18
|
-
render() {
|
19
|
-
console.log('this', this.class);
|
20
|
-
return html`
|
21
|
-
<div
|
22
|
-
key="${this.key}"
|
23
|
-
class="flex items-center cursor-pointer py-2 px-4 w-full text-sm text-gray-800
|
24
|
-
rounded-lg
|
25
|
-
hover:bg-gray-100
|
26
|
-
focus:outline-none
|
27
|
-
focus:bg-gray-100
|
28
|
-
dark:bg-neutral-900
|
29
|
-
dark:hover:bg-neutral-800
|
30
|
-
dark:text-neutral-200
|
31
|
-
dark:focus:bg-neutral-800
|
32
|
-
${this.class}
|
33
|
-
"
|
34
|
-
tabindex="${this.tabindex}"
|
35
|
-
aria-selected="${this.isSelected}"
|
36
|
-
data-selected="${this.isSelected}"
|
37
|
-
data-hs-combo-box-output-item=""
|
38
|
-
role="option"
|
39
|
-
@click="${this.onSelect}"
|
40
|
-
>
|
41
|
-
<span
|
42
|
-
class="${this.isSelected
|
43
|
-
? 'visible'
|
44
|
-
: 'invisible'} hs-combo-box-selected:block mr-2"
|
45
|
-
>
|
46
|
-
${tickIcon()}
|
47
|
-
</span>
|
48
|
-
<div class="flex justify-between items-center w-full">
|
49
|
-
<span
|
50
|
-
data-hs-combo-box-search-text="${this.searchText}"
|
51
|
-
data-hs-combo-box-value="${this.value}"
|
52
|
-
>
|
53
|
-
${this.searchText}
|
54
|
-
</span>
|
55
|
-
</div>
|
56
|
-
</div>
|
57
|
-
`;
|
58
|
-
}
|
59
|
-
}
|