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,58 +0,0 @@
|
|
1
|
-
import { LitElement, html, css, PropertyValues } from 'lit';
|
2
|
-
import { customElement, property } from 'lit/decorators.js';
|
3
|
-
import { popoverContentStyle } from './popover.style'; // Import the cva styles
|
4
|
-
import { TWStyles } from '../../../styles';
|
5
|
-
import { Popover } from './popover.atom';
|
6
|
-
import { cn } from '../../../helpers';
|
7
|
-
|
8
|
-
@customElement('rtg-popover-content')
|
9
|
-
export class PopoverContent extends LitElement {
|
10
|
-
static styles = [css``, TWStyles];
|
11
|
-
get _popover(): Popover | null {
|
12
|
-
let parent = this.parentElement;
|
13
|
-
// Traverse up the DOM tree to find the parent `Popover`
|
14
|
-
while (parent && !(parent instanceof Popover)) {
|
15
|
-
parent = parent.parentElement;
|
16
|
-
}
|
17
|
-
return parent;
|
18
|
-
}
|
19
|
-
|
20
|
-
@property({ type: String }) side: 'bottom' | 'left' | 'right' | 'top' =
|
21
|
-
'bottom';
|
22
|
-
private handleClickOutside(event: MouseEvent) {
|
23
|
-
// Check if the click was outside the popover
|
24
|
-
const slot = this.shadowRoot?.querySelector('slot');
|
25
|
-
if (slot) {
|
26
|
-
const assignedElements = slot.assignedElements({ flatten: true });
|
27
|
-
console.log(assignedElements[0]);
|
28
|
-
if (!assignedElements[0]?.contains(event.target as Node)) {
|
29
|
-
const popover = this._popover; // Get the parent popover
|
30
|
-
//@ts-ignore
|
31
|
-
popover.isOpen = false;
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
protected firstUpdated(_changedProperties: PropertyValues): void {
|
37
|
-
window.addEventListener('click', this.handleClickOutside.bind(this));
|
38
|
-
}
|
39
|
-
|
40
|
-
protected updated(_changedProperties: PropertyValues): void {
|
41
|
-
if (!this._popover?.isOpen) {
|
42
|
-
window.removeEventListener('click', this.handleClickOutside.bind(this));
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
render() {
|
47
|
-
const classes = popoverContentStyle({
|
48
|
-
state: 'open',
|
49
|
-
side: this.side,
|
50
|
-
});
|
51
|
-
|
52
|
-
return html`
|
53
|
-
<div class="${cn(classes)}">
|
54
|
-
<slot></slot>
|
55
|
-
</div>
|
56
|
-
`;
|
57
|
-
}
|
58
|
-
}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import { LitElement, html, css, PropertyValues } from 'lit';
|
2
|
-
import { customElement } from 'lit/decorators.js';
|
3
|
-
import { TWStyles } from '../../../styles';
|
4
|
-
import { Popover } from './popover.atom'; // Import the correct parent component
|
5
|
-
|
6
|
-
@customElement('rtg-popover-trigger') // Rename the custom element tag to avoid conflict
|
7
|
-
export class PopoverTrigger extends LitElement {
|
8
|
-
static styles = [css``, TWStyles];
|
9
|
-
|
10
|
-
handleClick = () => {
|
11
|
-
const popover = this._popover; // Get the parent popover
|
12
|
-
if (popover) {
|
13
|
-
popover.isOpen = !popover.isOpen;
|
14
|
-
}
|
15
|
-
};
|
16
|
-
|
17
|
-
protected firstUpdated(_changedProperties: PropertyValues): void {
|
18
|
-
super.firstUpdated(_changedProperties);
|
19
|
-
const slots = this.shadowRoot?.querySelector(
|
20
|
-
'slot[name="trigger-button"]'
|
21
|
-
) as HTMLSlotElement;
|
22
|
-
const assignedElements = slots?.assignedElements({ flatten: true });
|
23
|
-
if (assignedElements && assignedElements.length > 0) {
|
24
|
-
//@ts-ignore
|
25
|
-
assignedElements[0].click = this.handleClick;
|
26
|
-
// assignedElements[0].addEventListener('click', this.handleClick);
|
27
|
-
}
|
28
|
-
|
29
|
-
this.shadowRoot?.addEventListener('click', e => {
|
30
|
-
e.stopPropagation();
|
31
|
-
});
|
32
|
-
}
|
33
|
-
|
34
|
-
get _popover(): Popover | null {
|
35
|
-
let parent = this.parentElement;
|
36
|
-
// Traverse up the DOM tree to find the parent `Popover`
|
37
|
-
while (parent && !(parent instanceof Popover)) {
|
38
|
-
parent = parent.parentElement;
|
39
|
-
}
|
40
|
-
return parent;
|
41
|
-
}
|
42
|
-
|
43
|
-
render() {
|
44
|
-
return html`
|
45
|
-
<div style="width: fit-content;">
|
46
|
-
<slot name="trigger-button"></slot>
|
47
|
-
</div>
|
48
|
-
`;
|
49
|
-
}
|
50
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { LitElement, html, css, PropertyValues } from 'lit';
|
2
|
-
import { customElement, state } from 'lit/decorators.js';
|
3
|
-
import { TWStyles } from '../../../styles';
|
4
|
-
|
5
|
-
@customElement('rtg-popover')
|
6
|
-
export class Popover extends LitElement {
|
7
|
-
static styles = [css``, TWStyles];
|
8
|
-
|
9
|
-
@state() isOpen: boolean = false;
|
10
|
-
|
11
|
-
protected firstUpdated(_changedProperties: PropertyValues): void {
|
12
|
-
super.firstUpdated(_changedProperties);
|
13
|
-
// Add event listener for clicks outside the popover
|
14
|
-
}
|
15
|
-
|
16
|
-
protected updated(_changedProperties: PropertyValues): void {
|
17
|
-
super.updated(_changedProperties);
|
18
|
-
// Remove event listener when the popover is closed
|
19
|
-
}
|
20
|
-
|
21
|
-
render() {
|
22
|
-
return html`
|
23
|
-
<div>
|
24
|
-
<slot
|
25
|
-
name="trigger"
|
26
|
-
@click="${() => (this.isOpen = !this.isOpen)}"
|
27
|
-
></slot>
|
28
|
-
<div data-testid="popover-content-holder" ?hidden="${!this.isOpen}">
|
29
|
-
<slot name="content"></slot>
|
30
|
-
</div>
|
31
|
-
</div>
|
32
|
-
`;
|
33
|
-
}
|
34
|
-
}
|
@@ -1,79 +0,0 @@
|
|
1
|
-
import { html } from 'lit';
|
2
|
-
import { Meta, StoryFn } from '@storybook/web-components';
|
3
|
-
import './popover.atom';
|
4
|
-
import './popover-trigger';
|
5
|
-
import './popover-content';
|
6
|
-
import '../button/button.atom';
|
7
|
-
import '../label/label.atom';
|
8
|
-
import '../input/input.atom';
|
9
|
-
|
10
|
-
import { expect, within, userEvent } from '@storybook/test';
|
11
|
-
|
12
|
-
// Create a test to ensure the popover opens and closes correctly
|
13
|
-
const testPopoverBehavior = async (args: any, canvasElement: any) => {
|
14
|
-
const canvas = within(canvasElement);
|
15
|
-
|
16
|
-
// Click on the trigger button to open the popover
|
17
|
-
const trigger = await canvas.getByText(args.triggerLabel);
|
18
|
-
await userEvent.click(trigger);
|
19
|
-
|
20
|
-
// Ensure the popover content is visible
|
21
|
-
const popoverContent = await canvas.getByTestId('popover-content');
|
22
|
-
expect(popoverContent).toBeVisible();
|
23
|
-
|
24
|
-
// Click inside the popover content, it should remain open
|
25
|
-
await userEvent.click(popoverContent);
|
26
|
-
expect(popoverContent).toBeVisible();
|
27
|
-
|
28
|
-
// Click outside the popover, it should close
|
29
|
-
await userEvent.click(document.body); // Trigger a click outside
|
30
|
-
await new Promise(r => setTimeout(r, 100)); // Wait for state update
|
31
|
-
|
32
|
-
// Check if popover content is hidden
|
33
|
-
const hiddenPopoverContent = canvas.queryByTestId('popover-content-holder');
|
34
|
-
expect(hiddenPopoverContent).toBeNull();
|
35
|
-
};
|
36
|
-
|
37
|
-
export default {
|
38
|
-
title: 'components/atoms/popover',
|
39
|
-
component: 'rtg-popover',
|
40
|
-
tags: ['autodocs'],
|
41
|
-
argTypes: {
|
42
|
-
triggerLabel: { control: 'text', defaultValue: 'Click me' },
|
43
|
-
popoverContent: {
|
44
|
-
control: 'text',
|
45
|
-
defaultValue: 'This is the content inside the popover.',
|
46
|
-
},
|
47
|
-
},
|
48
|
-
} as Meta;
|
49
|
-
|
50
|
-
const Template: StoryFn = (args: any) => html`
|
51
|
-
<rtg-popover>
|
52
|
-
<!-- Trigger to open/close the popover -->
|
53
|
-
<rtg-popover-trigger slot="trigger">
|
54
|
-
<rtg-button variant="outline" slot="trigger-button"
|
55
|
-
>${args.triggerLabel}</rtg-button
|
56
|
-
>
|
57
|
-
</rtg-popover-trigger>
|
58
|
-
|
59
|
-
<!-- Popover content that will be shown or hidden -->
|
60
|
-
<rtg-popover-content
|
61
|
-
data-side="bottom"
|
62
|
-
data-testid="popover-content"
|
63
|
-
slot="content"
|
64
|
-
>
|
65
|
-
<div>
|
66
|
-
<p>${args.popoverContent}</p>
|
67
|
-
</div>
|
68
|
-
</rtg-popover-content>
|
69
|
-
</rtg-popover>
|
70
|
-
`;
|
71
|
-
|
72
|
-
export const Default = Template.bind({});
|
73
|
-
Default.args = {
|
74
|
-
triggerLabel: 'Click me',
|
75
|
-
popoverContent: 'This is the content inside the popover.',
|
76
|
-
};
|
77
|
-
Default.play = async ({ canvasElement }) => {
|
78
|
-
await testPopoverBehavior(Default.args, canvasElement);
|
79
|
-
};
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { cva } from 'class-variance-authority';
|
2
|
-
|
3
|
-
export const popoverRootStyle = cva('rtgpop-root');
|
4
|
-
|
5
|
-
export const popoverContentStyle = cva(
|
6
|
-
'z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none transition-transform transition-opacity',
|
7
|
-
{
|
8
|
-
variants: {
|
9
|
-
state: {
|
10
|
-
open: 'opacity-100 scale-100 duration-500', // 0.5 seconds for the transition
|
11
|
-
closed: 'opacity-0 scale-95 duration-500', // 0.5 seconds for the transition
|
12
|
-
},
|
13
|
-
side: {
|
14
|
-
bottom: 'translate-y-0',
|
15
|
-
left: 'translate-x-0',
|
16
|
-
right: 'translate-x-0',
|
17
|
-
top: 'translate-y-0',
|
18
|
-
},
|
19
|
-
},
|
20
|
-
defaultVariants: {
|
21
|
-
state: 'closed',
|
22
|
-
side: 'bottom',
|
23
|
-
},
|
24
|
-
}
|
25
|
-
);
|
@@ -1,29 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Toggle size.
|
3
|
-
*/
|
4
|
-
|
5
|
-
export enum TOGGLE_SIZE {
|
6
|
-
/**
|
7
|
-
* Small size
|
8
|
-
*/
|
9
|
-
SMALL = 'sm',
|
10
|
-
/**
|
11
|
-
* medium size
|
12
|
-
*/
|
13
|
-
MEDIUM = 'md',
|
14
|
-
/**
|
15
|
-
* Large size
|
16
|
-
*/
|
17
|
-
LARGE = 'lg',
|
18
|
-
}
|
19
|
-
|
20
|
-
export enum TOGGLE_VARIANT {
|
21
|
-
/**
|
22
|
-
* Default variant
|
23
|
-
*/
|
24
|
-
DEFAULT = 'default',
|
25
|
-
/**
|
26
|
-
* Outline variant
|
27
|
-
*/
|
28
|
-
OUTLINE = 'outline',
|
29
|
-
}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import { html } from 'lit-element';
|
2
|
-
import { customElement, property } from 'lit/decorators.js';
|
3
|
-
import { TOGGLE_SIZE, TOGGLE_VARIANT } from './defs';
|
4
|
-
import { TWStyles } from '../../../styles';
|
5
|
-
import { toggleStyle } from './toggle.style';
|
6
|
-
import { BaseElement, cn } from '../../../helpers';
|
7
|
-
import { spread } from '@open-wc/lit-helpers';
|
8
|
-
|
9
|
-
export { TOGGLE_SIZE, TOGGLE_VARIANT };
|
10
|
-
|
11
|
-
@customElement('rtg-toggle')
|
12
|
-
class Toggle extends BaseElement {
|
13
|
-
@property({ attribute: true, type: Boolean, reflect: true }) disabled = false;
|
14
|
-
@property({ attribute: true, type: Boolean, reflect: true }) checked = false;
|
15
|
-
@property({ attribute: true, type: Boolean, reflect: true }) required = false;
|
16
|
-
@property({ attribute: true, type: String }) variant: TOGGLE_VARIANT =
|
17
|
-
TOGGLE_VARIANT.DEFAULT;
|
18
|
-
@property({ attribute: true, type: String }) size: TOGGLE_SIZE =
|
19
|
-
TOGGLE_SIZE.SMALL;
|
20
|
-
|
21
|
-
static styles = [TWStyles];
|
22
|
-
static toggleVariants = toggleStyle;
|
23
|
-
protected getAttributesToExclude(): string[] {
|
24
|
-
return ['disabled', 'checked', 'variant', 'size', 'required'];
|
25
|
-
}
|
26
|
-
|
27
|
-
toggle() {
|
28
|
-
if (!this.disabled) {
|
29
|
-
this.checked = !this.checked;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
render() {
|
33
|
-
const attributes = this.getFilteredAttributes();
|
34
|
-
return html`
|
35
|
-
<button
|
36
|
-
type="button"
|
37
|
-
class="${cn(
|
38
|
-
Toggle.toggleVariants({
|
39
|
-
variant: this.variant,
|
40
|
-
size: this.size,
|
41
|
-
className: this.className,
|
42
|
-
})
|
43
|
-
)}"
|
44
|
-
aria-pressed=${this.checked}
|
45
|
-
data-state="${this.checked ? 'on' : 'off'}"
|
46
|
-
aria-label="Toggle bold"
|
47
|
-
@click=${this.toggle}
|
48
|
-
?disabled=${this.disabled}
|
49
|
-
?required=${this.required}
|
50
|
-
${spread(attributes)}
|
51
|
-
>
|
52
|
-
<slot></slot>
|
53
|
-
</button>
|
54
|
-
`;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
export { Toggle };
|
@@ -1,204 +0,0 @@
|
|
1
|
-
import { html } from 'lit';
|
2
|
-
import type { Meta, StoryObj } from '@storybook/web-components';
|
3
|
-
import { expect, within, waitFor, userEvent } from '@storybook/test';
|
4
|
-
import { Toggle, TOGGLE_SIZE, TOGGLE_VARIANT } from './toggle.atom';
|
5
|
-
// import '../button';
|
6
|
-
|
7
|
-
const meta: Meta = {
|
8
|
-
component: 'Toggle',
|
9
|
-
tags: ['autodocs'],
|
10
|
-
argTypes: {
|
11
|
-
variant: {
|
12
|
-
control: {
|
13
|
-
type: 'select',
|
14
|
-
},
|
15
|
-
options: Object.values(TOGGLE_VARIANT),
|
16
|
-
defaultValue: 'DEFAULT',
|
17
|
-
description: 'Choose the visual style of the toggle.',
|
18
|
-
table: {
|
19
|
-
defaultValue: { summary: 'DEFAULT' },
|
20
|
-
},
|
21
|
-
},
|
22
|
-
size: {
|
23
|
-
control: {
|
24
|
-
type: 'select',
|
25
|
-
},
|
26
|
-
options: Object.values(TOGGLE_SIZE),
|
27
|
-
description: 'Choose the size of the toggle.',
|
28
|
-
defaultValue: 'SMALL',
|
29
|
-
table: {
|
30
|
-
defaultValue: { summary: 'SMALL' },
|
31
|
-
},
|
32
|
-
},
|
33
|
-
disabled: {
|
34
|
-
control: 'boolean',
|
35
|
-
description: 'Disable the toggle to prevent interactions.',
|
36
|
-
table: {
|
37
|
-
defaultValue: { summary: 'false' },
|
38
|
-
},
|
39
|
-
},
|
40
|
-
checked: {
|
41
|
-
control: 'boolean',
|
42
|
-
description: 'Set the initial checked state of the toggle.',
|
43
|
-
table: {
|
44
|
-
defaultValue: { summary: 'false' },
|
45
|
-
},
|
46
|
-
},
|
47
|
-
required: {
|
48
|
-
control: 'boolean',
|
49
|
-
description: 'Mark the toggle as required.',
|
50
|
-
table: {
|
51
|
-
defaultValue: { summary: 'false' },
|
52
|
-
},
|
53
|
-
},
|
54
|
-
},
|
55
|
-
};
|
56
|
-
|
57
|
-
const testToggleBehavior = async (
|
58
|
-
args: any,
|
59
|
-
canvasElement: any,
|
60
|
-
mockHandler: any
|
61
|
-
) => {
|
62
|
-
const canvas = within(canvasElement);
|
63
|
-
const toggle = await waitFor(() => canvas.getByTestId('toggle-id'));
|
64
|
-
if (toggle.shadowRoot) {
|
65
|
-
const innerToggle = toggle.shadowRoot.querySelector(
|
66
|
-
'[data-testchild="children-id"]'
|
67
|
-
);
|
68
|
-
expect(innerToggle).toHaveAttribute('type', 'button');
|
69
|
-
// Test toggle state
|
70
|
-
if (args.checked) {
|
71
|
-
expect(innerToggle).toBeChecked();
|
72
|
-
} else {
|
73
|
-
expect(innerToggle).not.toBeChecked();
|
74
|
-
}
|
75
|
-
|
76
|
-
// Test toggle click behavior
|
77
|
-
if (!args.disabled && innerToggle) {
|
78
|
-
await userEvent.click(innerToggle);
|
79
|
-
if (mockHandler) {
|
80
|
-
expect(mockHandler).toHaveBeenCalled();
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
// Test toggle disabled state
|
85
|
-
if (args.disabled) {
|
86
|
-
expect(innerToggle).toBeDisabled();
|
87
|
-
} else {
|
88
|
-
expect(innerToggle).not.toBeDisabled();
|
89
|
-
}
|
90
|
-
|
91
|
-
// Test toggle variant classes
|
92
|
-
const expectedClasses = Toggle.toggleVariants({
|
93
|
-
variant: args.variant,
|
94
|
-
size: args.size,
|
95
|
-
className: '',
|
96
|
-
});
|
97
|
-
expect(innerToggle).toHaveClass(expectedClasses);
|
98
|
-
// Test toggle size classes
|
99
|
-
const expectedSizeClasses = Toggle.toggleVariants({
|
100
|
-
variant: args.variant,
|
101
|
-
size: args.size,
|
102
|
-
className: '',
|
103
|
-
});
|
104
|
-
expect(innerToggle).toHaveClass(expectedSizeClasses);
|
105
|
-
}
|
106
|
-
};
|
107
|
-
|
108
|
-
export default meta;
|
109
|
-
type Story = StoryObj;
|
110
|
-
|
111
|
-
export const Toggles: Story = {
|
112
|
-
args: {
|
113
|
-
variant: 'DEFAULT',
|
114
|
-
size: 'SMALL',
|
115
|
-
disabled: false,
|
116
|
-
checked: false,
|
117
|
-
required: false,
|
118
|
-
},
|
119
|
-
render: ({ variant, size, disabled, checked, required }) => html`
|
120
|
-
<rtg-toggle
|
121
|
-
?disabled=${disabled}
|
122
|
-
?checked=${checked}
|
123
|
-
?required=${required}
|
124
|
-
.variant=${variant}
|
125
|
-
.size=${size}
|
126
|
-
data-testid="toggle-id"
|
127
|
-
data-testchild="children-id"
|
128
|
-
>
|
129
|
-
<svg
|
130
|
-
xmlns="http://www.w3.org/2000/svg"
|
131
|
-
width="24"
|
132
|
-
height="24"
|
133
|
-
viewBox="0 0 24 24"
|
134
|
-
fill="none"
|
135
|
-
stroke="currentColor"
|
136
|
-
stroke-width="2"
|
137
|
-
stroke-linecap="round"
|
138
|
-
stroke-linejoin="round"
|
139
|
-
class="lucide lucide-bold h-4 w-4"
|
140
|
-
>
|
141
|
-
<path d="M14 12a4 4 0 0 0 0-8H6v8"></path>
|
142
|
-
<path d="M15 20a4 4 0 0 0 0-8H6v8Z"></path>
|
143
|
-
</svg>
|
144
|
-
</rtg-toggle>
|
145
|
-
`,
|
146
|
-
play: async ({ args, canvasElement }) => {
|
147
|
-
await testToggleBehavior(args, canvasElement, null);
|
148
|
-
},
|
149
|
-
};
|
150
|
-
|
151
|
-
export const RequiredToggle: Story = {
|
152
|
-
name: 'Required Toggle',
|
153
|
-
args: {
|
154
|
-
variant: 'DEFAULT',
|
155
|
-
size: 'SMALL',
|
156
|
-
disabled: false,
|
157
|
-
checked: false,
|
158
|
-
required: true,
|
159
|
-
},
|
160
|
-
render: ({ variant, size, disabled, checked, required }) => html`
|
161
|
-
<div>
|
162
|
-
<rtg-toggle
|
163
|
-
?disabled=${disabled}
|
164
|
-
?checked=${checked}
|
165
|
-
?required=${required}
|
166
|
-
.variant=${variant}
|
167
|
-
.size=${size}
|
168
|
-
data-testid="toggle-id"
|
169
|
-
data-testchild="children-id"
|
170
|
-
@click=${(e: Event) => {
|
171
|
-
const checkbox = e.target as HTMLInputElement;
|
172
|
-
const button = document.querySelector(
|
173
|
-
'rtg-button'
|
174
|
-
) as HTMLButtonElement;
|
175
|
-
if (button) {
|
176
|
-
button.disabled = required ? !checkbox.checked : false;
|
177
|
-
}
|
178
|
-
}}
|
179
|
-
>
|
180
|
-
<svg
|
181
|
-
xmlns="http://www.w3.org/2000/svg"
|
182
|
-
width="24"
|
183
|
-
height="24"
|
184
|
-
viewBox="0 0 24 24"
|
185
|
-
fill="none"
|
186
|
-
stroke="currentColor"
|
187
|
-
stroke-width="2"
|
188
|
-
stroke-linecap="round"
|
189
|
-
stroke-linejoin="round"
|
190
|
-
class="lucide lucide-italic h-4 w-4"
|
191
|
-
>
|
192
|
-
<line x1="19" x2="10" y1="4" y2="4"></line>
|
193
|
-
<line x1="14" x2="5" y1="20" y2="20"></line>
|
194
|
-
<line x1="15" x2="9" y1="4" y2="20"></line>
|
195
|
-
</svg>
|
196
|
-
</rtg-toggle>
|
197
|
-
</div>
|
198
|
-
|
199
|
-
<rtg-button ?disabled=${required && !checked}> send </rtg-button>
|
200
|
-
`,
|
201
|
-
play: async ({ args, canvasElement }) => {
|
202
|
-
await testToggleBehavior(args, canvasElement, null);
|
203
|
-
},
|
204
|
-
};
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { cva } from 'class-variance-authority';
|
2
|
-
|
3
|
-
export const toggleStyle = cva(
|
4
|
-
'inline-flex items-center justify-center 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 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground bg-transparent h-10 px-3',
|
5
|
-
{
|
6
|
-
variants: {
|
7
|
-
variant: {
|
8
|
-
default: ` hover:bg-muted hover:text-muted-foreground`,
|
9
|
-
outline: ` border border-input hover:bg-accent hover:text-accent-foreground`,
|
10
|
-
},
|
11
|
-
size: {
|
12
|
-
sm: 'h-9 px-2.5',
|
13
|
-
md: 'h-10 px-3',
|
14
|
-
lg: 'h-11 px-5',
|
15
|
-
},
|
16
|
-
},
|
17
|
-
defaultVariants: {
|
18
|
-
variant: 'default',
|
19
|
-
size: 'sm',
|
20
|
-
},
|
21
|
-
}
|
22
|
-
);
|