@kkkarsss/ui 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.storybook/main.d.ts +3 -0
- package/dist/.storybook/main.js +34 -0
- package/dist/.storybook/preview.d.ts +4 -0
- package/dist/.storybook/preview.js +19 -0
- package/dist/index.css +238 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/providers/alert/alert-context.d.ts +16 -0
- package/dist/providers/alert/alert-context.js +2 -0
- package/dist/providers/alert/alert-provider.d.ts +6 -0
- package/dist/providers/alert/alert-provider.js +50 -0
- package/dist/providers/alert/use-alerts.d.ts +1 -0
- package/dist/providers/alert/use-alerts.js +9 -0
- package/dist/providers/index.d.ts +9 -0
- package/dist/providers/index.js +9 -0
- package/dist/providers/theme/index.d.ts +3 -0
- package/dist/providers/theme/index.js +3 -0
- package/dist/providers/theme/theme-context.d.ts +7 -0
- package/dist/providers/theme/theme-context.js +6 -0
- package/dist/providers/theme/theme-provider.d.ts +9 -0
- package/dist/providers/theme/theme-provider.js +27 -0
- package/dist/providers/theme/use-theme.d.ts +4 -0
- package/dist/providers/theme/use-theme.js +8 -0
- package/dist/providers/widget/index.d.ts +3 -0
- package/dist/providers/widget/index.js +3 -0
- package/dist/providers/widget/use-widgets.d.ts +4 -0
- package/dist/providers/widget/use-widgets.js +8 -0
- package/dist/providers/widget/widget-context.d.ts +12 -0
- package/dist/providers/widget/widget-context.js +6 -0
- package/dist/providers/widget/widget-provider.d.ts +6 -0
- package/dist/providers/widget/widget-provider.js +13 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +4 -0
- package/dist/src/providers/alert/alert-context.d.ts +16 -0
- package/dist/src/providers/alert/alert-context.js +2 -0
- package/dist/src/providers/alert/alert-provider.d.ts +6 -0
- package/dist/src/providers/alert/alert-provider.js +50 -0
- package/dist/src/providers/alert/use-alerts.d.ts +1 -0
- package/dist/src/providers/alert/use-alerts.js +9 -0
- package/dist/src/providers/index.d.ts +9 -0
- package/dist/src/providers/index.js +9 -0
- package/dist/src/providers/theme/theme-context.d.ts +7 -0
- package/dist/src/providers/theme/theme-context.js +6 -0
- package/dist/src/providers/theme/theme-provider.d.ts +9 -0
- package/dist/src/providers/theme/theme-provider.js +27 -0
- package/dist/src/providers/theme/use-theme.d.ts +4 -0
- package/dist/src/providers/theme/use-theme.js +8 -0
- package/dist/src/providers/widget/use-widgets.d.ts +4 -0
- package/dist/src/providers/widget/use-widgets.js +8 -0
- package/dist/src/providers/widget/widget-context.d.ts +12 -0
- package/dist/src/providers/widget/widget-context.js +6 -0
- package/dist/src/providers/widget/widget-provider.d.ts +6 -0
- package/dist/src/providers/widget/widget-provider.js +15 -0
- package/dist/src/ui/controls/button/button.d.ts +10 -0
- package/dist/src/ui/controls/button/button.js +11 -0
- package/dist/src/ui/controls/button/button.stories.d.ts +9 -0
- package/dist/src/ui/controls/button/button.stories.js +38 -0
- package/dist/src/ui/controls/chip/chip.d.ts +12 -0
- package/dist/src/ui/controls/chip/chip.js +11 -0
- package/dist/src/ui/controls/chip/chip.stories.d.ts +9 -0
- package/dist/src/ui/controls/chip/chip.stories.js +42 -0
- package/dist/src/ui/controls/color-picker/color-picker.d.ts +8 -0
- package/dist/src/ui/controls/color-picker/color-picker.js +21 -0
- package/dist/src/ui/controls/color-picker/color-picker.stories.d.ts +7 -0
- package/dist/src/ui/controls/color-picker/color-picker.stories.js +21 -0
- package/dist/src/ui/controls/copy/copy.d.ts +6 -0
- package/dist/src/ui/controls/copy/copy.js +20 -0
- package/dist/src/ui/controls/copy/copy.stories.d.ts +7 -0
- package/dist/src/ui/controls/copy/copy.stories.js +20 -0
- package/dist/src/ui/controls/index.d.ts +7 -0
- package/dist/src/ui/controls/index.js +7 -0
- package/dist/src/ui/controls/input/input.d.ts +14 -0
- package/dist/src/ui/controls/input/input.js +12 -0
- package/dist/src/ui/controls/input/input.stories.d.ts +9 -0
- package/dist/src/ui/controls/input/input.stories.js +46 -0
- package/dist/src/ui/controls/select/select.d.ts +14 -0
- package/dist/src/ui/controls/select/select.js +80 -0
- package/dist/src/ui/controls/select/select.stories.d.ts +8 -0
- package/dist/src/ui/controls/select/select.stories.js +40 -0
- package/dist/src/ui/controls/textarea/textarea.d.ts +11 -0
- package/dist/src/ui/controls/textarea/textarea.js +20 -0
- package/dist/src/ui/controls/textarea/textarea.stories.d.ts +8 -0
- package/dist/src/ui/controls/textarea/textarea.stories.js +35 -0
- package/dist/src/ui/index.d.ts +3 -0
- package/dist/src/ui/index.js +3 -0
- package/dist/src/ui/information/block/block.d.ts +10 -0
- package/dist/src/ui/information/block/block.js +10 -0
- package/dist/src/ui/information/block/block.stories.d.ts +8 -0
- package/dist/src/ui/information/block/block.stories.js +38 -0
- package/dist/src/ui/information/cell/cell.d.ts +26 -0
- package/dist/src/ui/information/cell/cell.js +31 -0
- package/dist/src/ui/information/cell/cell.stories.d.ts +11 -0
- package/dist/src/ui/information/cell/cell.stories.js +62 -0
- package/dist/src/ui/information/cell/cells-block.d.ts +9 -0
- package/dist/src/ui/information/cell/cells-block.js +5 -0
- package/dist/src/ui/information/cell/cells-block.stories.d.ts +6 -0
- package/dist/src/ui/information/cell/cells-block.stories.js +20 -0
- package/dist/src/ui/information/index.d.ts +6 -0
- package/dist/src/ui/information/index.js +6 -0
- package/dist/src/ui/information/spinner/spinner.d.ts +2 -0
- package/dist/src/ui/information/spinner/spinner.js +5 -0
- package/dist/src/ui/information/spinner/spinner.stories.d.ts +6 -0
- package/dist/src/ui/information/spinner/spinner.stories.js +8 -0
- package/dist/src/ui/information/tag/tag.d.ts +6 -0
- package/dist/src/ui/information/tag/tag.js +7 -0
- package/dist/src/ui/information/tag/tag.stories.d.ts +8 -0
- package/dist/src/ui/information/tag/tag.stories.js +25 -0
- package/dist/src/ui/information/text/typo.d.ts +12 -0
- package/dist/src/ui/information/text/typo.js +41 -0
- package/dist/src/ui/information/text/typo.stories.d.ts +10 -0
- package/dist/src/ui/information/text/typo.stories.js +60 -0
- package/dist/src/ui/layout/dropdown/dropdown.d.ts +11 -0
- package/dist/src/ui/layout/dropdown/dropdown.js +59 -0
- package/dist/src/ui/layout/dropdown/dropdown.stories.d.ts +6 -0
- package/dist/src/ui/layout/dropdown/dropdown.stories.js +24 -0
- package/dist/src/ui/layout/flex/flex.d.ts +12 -0
- package/dist/src/ui/layout/flex/flex.js +36 -0
- package/dist/src/ui/layout/flex/flex.stories.d.ts +8 -0
- package/dist/src/ui/layout/flex/flex.stories.js +53 -0
- package/dist/src/ui/layout/icon-action/icon-action.d.ts +9 -0
- package/dist/src/ui/layout/icon-action/icon-action.js +11 -0
- package/dist/src/ui/layout/icon-action/icon-action.stories.d.ts +7 -0
- package/dist/src/ui/layout/icon-action/icon-action.stories.js +23 -0
- package/dist/src/ui/layout/index.d.ts +5 -0
- package/dist/src/ui/layout/index.js +5 -0
- package/dist/src/ui/layout/main-page-layout/main-page-layout.d.ts +7 -0
- package/dist/src/ui/layout/main-page-layout/main-page-layout.js +8 -0
- package/dist/src/ui/layout/main-page-layout/main-page-layout.stories.d.ts +6 -0
- package/dist/src/ui/layout/main-page-layout/main-page-layout.stories.js +19 -0
- package/dist/src/ui/layout/offset/offset.d.ts +6 -0
- package/dist/src/ui/layout/offset/offset.js +10 -0
- package/dist/src/ui/layout/offset/offset.stories.d.ts +8 -0
- package/dist/src/ui/layout/offset/offset.stories.js +33 -0
- package/dist/src/utils/classes.d.ts +1 -0
- package/dist/src/utils/classes.js +1 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/stories/Button.d.ts +15 -0
- package/dist/stories/Button.js +7 -0
- package/dist/stories/Button.stories.d.ts +23 -0
- package/dist/stories/Button.stories.js +44 -0
- package/dist/stories/Header.d.ts +12 -0
- package/dist/stories/Header.js +4 -0
- package/dist/stories/Header.stories.d.ts +18 -0
- package/dist/stories/Header.stories.js +26 -0
- package/dist/stories/Page.d.ts +3 -0
- package/dist/stories/Page.js +8 -0
- package/dist/stories/Page.stories.d.ts +12 -0
- package/dist/stories/Page.stories.js +24 -0
- package/dist/ui/controls/button/button.d.ts +10 -0
- package/dist/ui/controls/button/button.js +11 -0
- package/dist/ui/controls/button/button.stories.d.ts +9 -0
- package/dist/ui/controls/button/button.stories.js +38 -0
- package/dist/ui/controls/chip/chip.d.ts +12 -0
- package/dist/ui/controls/chip/chip.js +11 -0
- package/dist/ui/controls/chip/chip.stories.d.ts +9 -0
- package/dist/ui/controls/chip/chip.stories.js +42 -0
- package/dist/ui/controls/color-picker/color-picker.d.ts +8 -0
- package/dist/ui/controls/color-picker/color-picker.js +21 -0
- package/dist/ui/controls/color-picker/color-picker.stories.d.ts +7 -0
- package/dist/ui/controls/color-picker/color-picker.stories.js +21 -0
- package/dist/ui/controls/copy/copy.d.ts +6 -0
- package/dist/ui/controls/copy/copy.js +20 -0
- package/dist/ui/controls/copy/copy.stories.d.ts +7 -0
- package/dist/ui/controls/copy/copy.stories.js +20 -0
- package/dist/ui/controls/date-input/date-input.d.ts +10 -0
- package/dist/ui/controls/date-input/date-input.js +25 -0
- package/dist/ui/controls/date-picker/date-picker.d.ts +7 -0
- package/dist/ui/controls/date-picker/date-picker.js +32 -0
- package/dist/ui/controls/index.d.ts +9 -0
- package/dist/ui/controls/index.js +9 -0
- package/dist/ui/controls/input/input.d.ts +15 -0
- package/dist/ui/controls/input/input.js +12 -0
- package/dist/ui/controls/input/input.stories.d.ts +9 -0
- package/dist/ui/controls/input/input.stories.js +46 -0
- package/dist/ui/controls/select/select.d.ts +14 -0
- package/dist/ui/controls/select/select.js +80 -0
- package/dist/ui/controls/select/select.stories.d.ts +8 -0
- package/dist/ui/controls/select/select.stories.js +40 -0
- package/dist/ui/controls/textarea/textarea.d.ts +11 -0
- package/dist/ui/controls/textarea/textarea.js +20 -0
- package/dist/ui/controls/textarea/textarea.stories.d.ts +8 -0
- package/dist/ui/controls/textarea/textarea.stories.js +35 -0
- package/dist/ui/controls/theme-toggle/theme-toggle.d.ts +2 -0
- package/dist/ui/controls/theme-toggle/theme-toggle.js +10 -0
- package/dist/ui/index.d.ts +3 -0
- package/dist/ui/index.js +3 -0
- package/dist/ui/information/block/block.d.ts +13 -0
- package/dist/ui/information/block/block.js +10 -0
- package/dist/ui/information/block/block.stories.d.ts +9 -0
- package/dist/ui/information/block/block.stories.js +47 -0
- package/dist/ui/information/calendar-like/calendar-like.d.ts +24 -0
- package/dist/ui/information/calendar-like/calendar-like.js +71 -0
- package/dist/ui/information/cell/cell.d.ts +26 -0
- package/dist/ui/information/cell/cell.js +31 -0
- package/dist/ui/information/cell/cell.stories.d.ts +11 -0
- package/dist/ui/information/cell/cell.stories.js +62 -0
- package/dist/ui/information/cell/cells-block.d.ts +9 -0
- package/dist/ui/information/cell/cells-block.js +5 -0
- package/dist/ui/information/cell/cells-block.stories.d.ts +6 -0
- package/dist/ui/information/cell/cells-block.stories.js +20 -0
- package/dist/ui/information/index.d.ts +8 -0
- package/dist/ui/information/index.js +8 -0
- package/dist/ui/information/not-found/not-found.d.ts +2 -0
- package/dist/ui/information/not-found/not-found.js +6 -0
- package/dist/ui/information/spinner/spinner.d.ts +2 -0
- package/dist/ui/information/spinner/spinner.js +5 -0
- package/dist/ui/information/spinner/spinner.stories.d.ts +6 -0
- package/dist/ui/information/spinner/spinner.stories.js +8 -0
- package/dist/ui/information/tag/tag.d.ts +6 -0
- package/dist/ui/information/tag/tag.js +7 -0
- package/dist/ui/information/tag/tag.stories.d.ts +8 -0
- package/dist/ui/information/tag/tag.stories.js +25 -0
- package/dist/ui/information/text/typo.d.ts +13 -0
- package/dist/ui/information/text/typo.js +41 -0
- package/dist/ui/information/text/typo.stories.d.ts +10 -0
- package/dist/ui/information/text/typo.stories.js +60 -0
- package/dist/ui/information/typo.d.ts +12 -0
- package/dist/ui/information/typo.js +41 -0
- package/dist/ui/layout/dropdown/dropdown.d.ts +11 -0
- package/dist/ui/layout/dropdown/dropdown.js +44 -0
- package/dist/ui/layout/dropdown/dropdown.stories.d.ts +6 -0
- package/dist/ui/layout/dropdown/dropdown.stories.js +24 -0
- package/dist/ui/layout/flex/flex.d.ts +13 -0
- package/dist/ui/layout/flex/flex.js +36 -0
- package/dist/ui/layout/flex/flex.stories.d.ts +8 -0
- package/dist/ui/layout/flex/flex.stories.js +53 -0
- package/dist/ui/layout/icon-action/icon-action.d.ts +9 -0
- package/dist/ui/layout/icon-action/icon-action.js +11 -0
- package/dist/ui/layout/icon-action/icon-action.stories.d.ts +7 -0
- package/dist/ui/layout/icon-action/icon-action.stories.js +23 -0
- package/dist/ui/layout/index.d.ts +5 -0
- package/dist/ui/layout/index.js +5 -0
- package/dist/ui/layout/main-page-layout/main-page-layout.d.ts +7 -0
- package/dist/ui/layout/main-page-layout/main-page-layout.js +8 -0
- package/dist/ui/layout/main-page-layout/main-page-layout.stories.d.ts +6 -0
- package/dist/ui/layout/main-page-layout/main-page-layout.stories.js +19 -0
- package/dist/ui/layout/offset/offset.d.ts +7 -0
- package/dist/ui/layout/offset/offset.js +10 -0
- package/dist/ui/layout/offset/offset.stories.d.ts +8 -0
- package/dist/ui/layout/offset/offset.stories.js +33 -0
- package/dist/utils/classes.d.ts +1 -0
- package/dist/utils/classes.js +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Header } from './Header';
|
|
4
|
+
import './page.css';
|
|
5
|
+
export const Page = () => {
|
|
6
|
+
const [user, setUser] = React.useState();
|
|
7
|
+
return (_jsxs("article", { children: [_jsx(Header, { user: user, onLogin: () => setUser({ name: 'Jane Doe' }), onLogout: () => setUser(undefined), onCreateAccount: () => setUser({ name: 'Jane Doe' }) }), _jsxs("section", { className: "storybook-page", children: [_jsx("h2", { children: "Pages in Storybook" }), _jsxs("p", { children: ["We recommend building UIs with a", ' ', _jsx("a", { href: "https://componentdriven.org", target: "_blank", rel: "noopener noreferrer", children: _jsx("strong", { children: "component-driven" }) }), ' ', "process starting with atomic components and ending with pages."] }), _jsx("p", { children: "Render pages with mock data. This makes it easy to build and review page states without needing to navigate to them in your app. Here are some handy patterns for managing page data in Storybook:" }), _jsxs("ul", { children: [_jsx("li", { children: "Use a higher-level connected component. Storybook helps you compose such data from the \"args\" of child component stories" }), _jsx("li", { children: "Assemble data in the page component from your services. You can mock these services out using Storybook." })] }), _jsxs("p", { children: ["Get a guided tutorial on component-driven development at", ' ', _jsx("a", { href: "https://storybook.js.org/tutorials/", target: "_blank", rel: "noopener noreferrer", children: "Storybook tutorials" }), ". Read more in the", ' ', _jsx("a", { href: "https://storybook.js.org/docs", target: "_blank", rel: "noopener noreferrer", children: "docs" }), "."] }), _jsxs("div", { className: "tip-wrapper", children: [_jsx("span", { className: "tip", children: "Tip" }), " Adjust the width of the canvas with the", ' ', _jsx("svg", { width: "10", height: "10", viewBox: "0 0 12 12", xmlns: "http://www.w3.org/2000/svg", children: _jsx("g", { fill: "none", fillRule: "evenodd", children: _jsx("path", { d: "M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z", id: "a", fill: "#999" }) }) }), "Viewports addon in the toolbar"] })] })] }));
|
|
8
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react-vite';
|
|
2
|
+
declare const meta: {
|
|
3
|
+
title: string;
|
|
4
|
+
component: import("react").FC<{}>;
|
|
5
|
+
parameters: {
|
|
6
|
+
layout: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj<typeof meta>;
|
|
11
|
+
export declare const LoggedOut: Story;
|
|
12
|
+
export declare const LoggedIn: Story;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
2
|
+
import { Page } from './Page';
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Example/Page',
|
|
5
|
+
component: Page,
|
|
6
|
+
parameters: {
|
|
7
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
8
|
+
layout: 'fullscreen',
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export const LoggedOut = {};
|
|
13
|
+
// More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
|
|
14
|
+
export const LoggedIn = {
|
|
15
|
+
play: async ({ canvasElement }) => {
|
|
16
|
+
const canvas = within(canvasElement);
|
|
17
|
+
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
|
18
|
+
await expect(loginButton).toBeInTheDocument();
|
|
19
|
+
await userEvent.click(loginButton);
|
|
20
|
+
await expect(loginButton).not.toBeInTheDocument();
|
|
21
|
+
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
|
22
|
+
await expect(logoutButton).toBeInTheDocument();
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FC, type ReactNode } from 'react';
|
|
2
|
+
type ButtonVariant = 'active' | 'secondary' | 'selling';
|
|
3
|
+
type ButtonProps = {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
onClick?: VoidFunction;
|
|
6
|
+
variant?: ButtonVariant;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const Button: FC<ButtonProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jc } from '../../../utils';
|
|
3
|
+
import { Typo } from '../../information';
|
|
4
|
+
const variantMap = {
|
|
5
|
+
active: 'bg-[var(--primary)] text-[var(--primary-foreground)]',
|
|
6
|
+
secondary: 'bg-secondary text-secondary-foreground border border-[var(--border)]',
|
|
7
|
+
selling: 'bg-accent text-accent-foreground',
|
|
8
|
+
};
|
|
9
|
+
export const Button = ({ children, onClick, variant = 'active', disabled = false }) => {
|
|
10
|
+
return (_jsx("button", { className: jc('w-auto px-4 py-2 text-[14px] font-medium border border-transparent cursor-pointer outline-none transition-opacity duration-200', 'disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none hover:not-disabled:opacity-90', variantMap[variant]), onClick: onClick, disabled: disabled, children: _jsx(Typo, { size: 'm', children: children }) }));
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { Button } from './button';
|
|
3
|
+
declare const meta: Meta<typeof Button>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Active: Story;
|
|
7
|
+
export declare const Secondary: Story;
|
|
8
|
+
export declare const Selling: Story;
|
|
9
|
+
export declare const Disabled: Story;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Button } from './button';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Controls/Button',
|
|
4
|
+
component: Button,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
argTypes: {
|
|
7
|
+
onClick: { action: 'clicked' },
|
|
8
|
+
variant: {
|
|
9
|
+
control: 'select',
|
|
10
|
+
options: ['active', 'secondary', 'selling'],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export default meta;
|
|
15
|
+
export const Active = {
|
|
16
|
+
args: {
|
|
17
|
+
children: 'Активная кнопка',
|
|
18
|
+
variant: 'active',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const Secondary = {
|
|
22
|
+
args: {
|
|
23
|
+
children: 'Вторичная кнопка',
|
|
24
|
+
variant: 'secondary',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export const Selling = {
|
|
28
|
+
args: {
|
|
29
|
+
children: 'Продающая кнопка',
|
|
30
|
+
variant: 'selling',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export const Disabled = {
|
|
34
|
+
args: {
|
|
35
|
+
children: 'Отключенная кнопка',
|
|
36
|
+
disabled: true,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LucideProps } from 'lucide-react';
|
|
2
|
+
import { type FC, type ReactElement } from 'react';
|
|
3
|
+
import { type TTypoProps } from '../../information';
|
|
4
|
+
type TVariant = 'default' | 'secondary' | 'accent';
|
|
5
|
+
type TProps = {
|
|
6
|
+
variant?: TVariant;
|
|
7
|
+
onClick?: VoidFunction;
|
|
8
|
+
accLeft?: FC<LucideProps>;
|
|
9
|
+
children: ReactElement<TTypoProps>;
|
|
10
|
+
};
|
|
11
|
+
export declare const Chip: FC<TProps>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Activity, createElement } from 'react';
|
|
3
|
+
import { jc } from '../../../utils';
|
|
4
|
+
const variantMap = {
|
|
5
|
+
default: 'bg-secondary text-secondary-foreground',
|
|
6
|
+
accent: 'bg-accent text-accent-foreground',
|
|
7
|
+
secondary: 'bg-transparent text-secondary-foreground border border-secondary-foreground',
|
|
8
|
+
};
|
|
9
|
+
export const Chip = ({ children, onClick, accLeft, variant = 'default' }) => {
|
|
10
|
+
return (_jsxs("button", { onClick: onClick, className: jc('flex items-center text-nowrap gap-[5px] w-min px-2 py-1 rounded-2xl outline-none border-none cursor-pointer text-[14px]', variantMap[variant]), children: [_jsx(Activity, { mode: accLeft ? 'visible' : 'hidden', children: accLeft ? createElement(accLeft, { size: 14, color: 'white', strokeWidth: 3 }) : null }), children] }));
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { Chip } from './chip';
|
|
3
|
+
declare const meta: Meta<typeof Chip>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const Accent: Story;
|
|
8
|
+
export declare const Secondary: Story;
|
|
9
|
+
export declare const WithIcon: Story;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Mail } from 'lucide-react';
|
|
3
|
+
import { Chip } from './chip';
|
|
4
|
+
import { Typo } from '../../information';
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Controls/Chip',
|
|
7
|
+
component: Chip,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
argTypes: {
|
|
10
|
+
onClick: { action: 'clicked' },
|
|
11
|
+
variant: {
|
|
12
|
+
control: 'select',
|
|
13
|
+
options: ['default', 'secondary', 'accent'],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export default meta;
|
|
18
|
+
export const Default = {
|
|
19
|
+
args: {
|
|
20
|
+
children: _jsx(Typo, { children: "Chip Content" }),
|
|
21
|
+
variant: 'default',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export const Accent = {
|
|
25
|
+
args: {
|
|
26
|
+
children: _jsx(Typo, { children: "Accent Chip" }),
|
|
27
|
+
variant: 'accent',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export const Secondary = {
|
|
31
|
+
args: {
|
|
32
|
+
children: _jsx(Typo, { children: "Secondary Chip" }),
|
|
33
|
+
variant: 'secondary',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
export const WithIcon = {
|
|
37
|
+
args: {
|
|
38
|
+
children: _jsx(Typo, { children: "Email" }),
|
|
39
|
+
accLeft: Mail,
|
|
40
|
+
variant: 'accent',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from '../../../providers';
|
|
3
|
+
import { jc } from '../../../utils';
|
|
4
|
+
import { Typo } from '../../information';
|
|
5
|
+
import { Flex, Offset } from '../../layout';
|
|
6
|
+
const COLORS = [
|
|
7
|
+
'#3b82f6', // blue
|
|
8
|
+
'#ef4444', // red
|
|
9
|
+
'#10b981', // green
|
|
10
|
+
'#f59e0b', // amber
|
|
11
|
+
'#6366f1', // indigo
|
|
12
|
+
'#8b5cf6', // violet
|
|
13
|
+
'#ec4899', // pink
|
|
14
|
+
'#14b8a6', // teal
|
|
15
|
+
'#f97316', // orange
|
|
16
|
+
'#71717a', // zinc
|
|
17
|
+
];
|
|
18
|
+
export const ColorPicker = ({ value, onChange, label }) => {
|
|
19
|
+
const { theme } = useTheme();
|
|
20
|
+
return (_jsxs("div", { className: "flex flex-col gap-[2px]", children: [label && (_jsx(Offset, { children: _jsx(Typo, { size: 's', color: 'secondary', weight: '500', children: label }) })), _jsx(Offset, { children: _jsx(Flex, { direction: 'row', gap: '8px', offset: '4px', children: COLORS.map((color) => (_jsx("button", { type: "button", className: jc('h-6 w-6 rounded-full border-2 transition-transform hover:scale-110 active:scale-95', value === color ? (theme === 'light' ? 'border-foreground' : `border-white`) : 'border-transparent'), style: { backgroundColor: color }, onClick: () => onChange(color), title: color }, color))) }) })] }));
|
|
21
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { ColorPicker } from './color-picker';
|
|
3
|
+
declare const meta: Meta<typeof ColorPicker>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithoutLabel: Story;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ColorPicker } from './color-picker';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Controls/ColorPicker',
|
|
4
|
+
component: ColorPicker,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
argTypes: {
|
|
7
|
+
onChange: { action: 'changed' },
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const Default = {
|
|
12
|
+
args: {
|
|
13
|
+
value: '#3b82f6',
|
|
14
|
+
label: 'Выберите цвет',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export const WithoutLabel = {
|
|
18
|
+
args: {
|
|
19
|
+
value: '#ef4444',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
export const Copy = ({ toCopy, children }) => {
|
|
4
|
+
const [active, setActive] = useState(false);
|
|
5
|
+
const handleCopy = async () => {
|
|
6
|
+
try {
|
|
7
|
+
await navigator.clipboard.writeText(toCopy);
|
|
8
|
+
setActive(true);
|
|
9
|
+
setTimeout(() => setActive(false), 150);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
console.error('Failed to copy:', e);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
return (_jsx("span", { onClick: handleCopy, className: `
|
|
16
|
+
cursor-pointer select-none
|
|
17
|
+
transition-opacity duration-150
|
|
18
|
+
${active ? 'opacity-70' : 'opacity-100'}
|
|
19
|
+
`, children: children ?? toCopy }));
|
|
20
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { Copy } from './copy';
|
|
3
|
+
declare const meta: Meta<typeof Copy>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const JustText: Story;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Copy } from './copy';
|
|
3
|
+
import { Typo } from '../../information';
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Controls/Copy',
|
|
6
|
+
component: Copy,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
export const Default = {
|
|
11
|
+
args: {
|
|
12
|
+
toCopy: 'Hello World',
|
|
13
|
+
children: _jsx(Typo, { children: "Click to copy \"Hello World\"" }),
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
export const JustText = {
|
|
17
|
+
args: {
|
|
18
|
+
toCopy: 'Plain text copy',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
export type TDateInputProps = {
|
|
3
|
+
value: string;
|
|
4
|
+
onChange: (value: string) => void;
|
|
5
|
+
label?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
size?: 's' | 'm' | 'l';
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const DateInput: FC<TDateInputProps>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Calendar } from 'lucide-react';
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import { Dropdown } from '../../layout';
|
|
5
|
+
import { DatePicker } from '../date-picker/date-picker';
|
|
6
|
+
import { Input } from '../input/input';
|
|
7
|
+
export const DateInput = ({ value, onChange, label, placeholder, size = 'm', disabled }) => {
|
|
8
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const handleDateSelect = (date) => {
|
|
11
|
+
if (date) {
|
|
12
|
+
const year = date.getFullYear();
|
|
13
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
14
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
15
|
+
onChange(`${year}-${month}-${day}`);
|
|
16
|
+
setIsOpen(false);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const selectedDate = value ? new Date(value) : undefined;
|
|
20
|
+
return (_jsxs("div", { ref: containerRef, className: "relative w-full", children: [_jsx(Input, { label: label, value: value, onChange: (e) => onChange(e.target.value), type: "text", placeholder: placeholder || 'YYYY-MM-DD', size: size, disabled: disabled, rightAcc: _jsx("div", { className: "flex items-center h-full", children: _jsx(Calendar, { size: 16, className: "cursor-pointer text-secondary transition-colors hover:text-accent", onClick: (e) => {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
setIsOpen(!isOpen);
|
|
24
|
+
} }) }) }), _jsx(Dropdown, { isOpen: isOpen, onClose: () => setIsOpen(false), anchorRef: containerRef, children: _jsx(DatePicker, { selected: selectedDate, onSelect: handleDateSelect }) })] }));
|
|
25
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DayPicker } from 'react-day-picker';
|
|
3
|
+
import 'react-day-picker/dist/style.css';
|
|
4
|
+
export const DatePicker = ({ selected, onSelect }) => {
|
|
5
|
+
return (_jsx("div", { className: `rounded-lg p-4 shadow-md`, style: {
|
|
6
|
+
background: `var(--background-accent)`,
|
|
7
|
+
color: `var(--foreground)`,
|
|
8
|
+
boxShadow: `0 4px 6px var(--shadow)`,
|
|
9
|
+
}, children: _jsx(DayPicker, { mode: "single", selected: selected, onSelect: onSelect, className: "react-day-picker", styles: {
|
|
10
|
+
caption: {
|
|
11
|
+
color: `var(--foreground)`,
|
|
12
|
+
},
|
|
13
|
+
day: {
|
|
14
|
+
borderRadius: '0.375rem',
|
|
15
|
+
color: `var(--foreground)`,
|
|
16
|
+
},
|
|
17
|
+
day_selected: {
|
|
18
|
+
backgroundColor: `var(--accent)`,
|
|
19
|
+
color: `var(--accent-foreground)`,
|
|
20
|
+
},
|
|
21
|
+
day_today: {
|
|
22
|
+
backgroundColor: `var(--background-secondary)`,
|
|
23
|
+
color: `var(--foreground)`,
|
|
24
|
+
},
|
|
25
|
+
day_outside: {
|
|
26
|
+
color: `var(--secondary-foreground)`,
|
|
27
|
+
},
|
|
28
|
+
root: {
|
|
29
|
+
background: `var(--background-accent)`,
|
|
30
|
+
},
|
|
31
|
+
} }) }));
|
|
32
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './button/button';
|
|
2
|
+
export * from './chip/chip';
|
|
3
|
+
export * from './color-picker/color-picker';
|
|
4
|
+
export * from './copy/copy';
|
|
5
|
+
export * from './input/input';
|
|
6
|
+
export * from './select/select';
|
|
7
|
+
export * from './textarea/textarea';
|
|
8
|
+
export * from './date-picker/date-picker';
|
|
9
|
+
export * from './date-input/date-input';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './button/button';
|
|
2
|
+
export * from './chip/chip';
|
|
3
|
+
export * from './color-picker/color-picker';
|
|
4
|
+
export * from './copy/copy';
|
|
5
|
+
export * from './input/input';
|
|
6
|
+
export * from './select/select';
|
|
7
|
+
export * from './textarea/textarea';
|
|
8
|
+
export * from './date-picker/date-picker';
|
|
9
|
+
export * from './date-input/date-input';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChangeEvent, FC, MouseEvent, ReactNode } from 'react';
|
|
2
|
+
export type TInputProps = {
|
|
3
|
+
value: string;
|
|
4
|
+
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
5
|
+
onClick?: (e: MouseEvent<HTMLInputElement>) => void;
|
|
6
|
+
label?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
size?: 's' | 'm' | 'l';
|
|
11
|
+
autoFocus?: boolean;
|
|
12
|
+
type?: 'text' | 'date' | 'number' | 'password';
|
|
13
|
+
rightAcc?: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export declare const Input: FC<TInputProps>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jc } from '../../../utils';
|
|
3
|
+
import { Typo } from '../../information';
|
|
4
|
+
import { Offset } from '../../layout';
|
|
5
|
+
const sizeMap = {
|
|
6
|
+
s: 'text-[12px] font-normal placeholder:text-[12px] placeholder:font-normal',
|
|
7
|
+
m: 'text-[14px] font-medium placeholder:text-[14px] placeholder:font-medium',
|
|
8
|
+
l: 'text-[16px] font-medium placeholder:text-[16px] placeholder:font-medium',
|
|
9
|
+
};
|
|
10
|
+
export const Input = ({ onChange, onClick, label, value, required, disabled, placeholder, size = 's', autoFocus, type = 'text', rightAcc, }) => {
|
|
11
|
+
return (_jsxs("div", { className: "relative flex w-full", children: [_jsxs("label", { className: "flex w-full cursor-pointer flex-col gap-[2px]", children: [label && (_jsx(Offset, { className: rightAcc ? 'pr-10' : undefined, children: _jsx(Typo, { size: 's', color: 'secondary', weight: '500', children: label }) })), _jsx("div", { className: "relative flex items-center", children: _jsx("input", { className: jc('w-full cursor-text rounded-sm border-none bg-inherit px-4 pb-2 pt-1 outline-none transition-all duration-200 placeholder:text-secondary-foreground', sizeMap[size], rightAcc ? 'pr-10' : undefined), type: type, placeholder: placeholder, value: value, onChange: onChange, onClick: onClick, disabled: disabled, required: required, autoFocus: autoFocus }) })] }), rightAcc && _jsx("div", { className: "absolute right-3 flex items-center h-full top-0", children: rightAcc })] }));
|
|
12
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { Input } from './input';
|
|
3
|
+
declare const meta: Meta<typeof Input>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithValue: Story;
|
|
8
|
+
export declare const Password: Story;
|
|
9
|
+
export declare const Disabled: Story;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Input } from './input';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Controls/Input',
|
|
4
|
+
component: Input,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
argTypes: {
|
|
7
|
+
onChange: { action: 'changed' },
|
|
8
|
+
size: {
|
|
9
|
+
control: 'select',
|
|
10
|
+
options: ['s', 'm', 'l'],
|
|
11
|
+
},
|
|
12
|
+
type: {
|
|
13
|
+
control: 'select',
|
|
14
|
+
options: ['text', 'date', 'number', 'password'],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export default meta;
|
|
19
|
+
export const Default = {
|
|
20
|
+
args: {
|
|
21
|
+
label: 'Label',
|
|
22
|
+
value: '',
|
|
23
|
+
placeholder: 'Placeholder...',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export const WithValue = {
|
|
27
|
+
args: {
|
|
28
|
+
label: 'Username',
|
|
29
|
+
value: 'JohnDoe',
|
|
30
|
+
placeholder: 'Enter username',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export const Password = {
|
|
34
|
+
args: {
|
|
35
|
+
label: 'Password',
|
|
36
|
+
value: 'secret',
|
|
37
|
+
type: 'password',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export const Disabled = {
|
|
41
|
+
args: {
|
|
42
|
+
label: 'Disabled Input',
|
|
43
|
+
value: 'Cannot edit this',
|
|
44
|
+
disabled: true,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
export type TSelectOption<T> = {
|
|
3
|
+
value: T;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
export type TSelectProps<T> = {
|
|
7
|
+
options: TSelectOption<T>[];
|
|
8
|
+
value: T;
|
|
9
|
+
onChange: (value: T) => void;
|
|
10
|
+
label?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function Select<T = string>({ options, value, onChange, label, placeholder, disabled, }: TSelectProps<T>): ReactElement;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDown } from 'lucide-react';
|
|
3
|
+
import { useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { jc } from '../../../utils';
|
|
5
|
+
import { Cell, Typo } from '../../information';
|
|
6
|
+
import { Dropdown, Flex, Offset } from '../../layout';
|
|
7
|
+
import { Input } from '../input/input';
|
|
8
|
+
export function Select({ options, value, onChange, label, placeholder = 'Select...', disabled, }) {
|
|
9
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
10
|
+
const [search, setSearch] = useState('');
|
|
11
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
12
|
+
const containerRef = useRef(null);
|
|
13
|
+
const selectedOption = useMemo(() => options.find((opt) => opt.value === value), [options, value]);
|
|
14
|
+
const filteredOptions = useMemo(() => {
|
|
15
|
+
if (!search)
|
|
16
|
+
return options;
|
|
17
|
+
return options.filter((opt) => opt.label.toLowerCase().includes(search.toLowerCase()));
|
|
18
|
+
}, [options, search]);
|
|
19
|
+
const handleSelect = (option) => {
|
|
20
|
+
onChange(option.value);
|
|
21
|
+
setIsOpen(false);
|
|
22
|
+
setSearch('');
|
|
23
|
+
setActiveIndex(-1);
|
|
24
|
+
};
|
|
25
|
+
const handleToggle = () => {
|
|
26
|
+
if (disabled)
|
|
27
|
+
return;
|
|
28
|
+
const nextOpen = !isOpen;
|
|
29
|
+
setIsOpen(nextOpen);
|
|
30
|
+
setActiveIndex(-1);
|
|
31
|
+
if (!nextOpen) {
|
|
32
|
+
setSearch('');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const handleKeyDown = (e) => {
|
|
36
|
+
if (disabled)
|
|
37
|
+
return;
|
|
38
|
+
if (!isOpen) {
|
|
39
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Enter') {
|
|
40
|
+
setIsOpen(true);
|
|
41
|
+
setActiveIndex(-1);
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
switch (e.key) {
|
|
47
|
+
case 'ArrowDown':
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
setActiveIndex((prev) => (prev < filteredOptions.length - 1 ? prev + 1 : prev));
|
|
50
|
+
break;
|
|
51
|
+
case 'ArrowUp':
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
setActiveIndex((prev) => (prev > 0 ? prev - 1 : 0));
|
|
54
|
+
break;
|
|
55
|
+
case 'Enter':
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
if (activeIndex >= 0 && activeIndex < filteredOptions.length) {
|
|
58
|
+
handleSelect(filteredOptions[activeIndex]);
|
|
59
|
+
}
|
|
60
|
+
else if (filteredOptions.length === 1) {
|
|
61
|
+
handleSelect(filteredOptions[0]);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case 'Escape':
|
|
65
|
+
setIsOpen(false);
|
|
66
|
+
setActiveIndex(-1);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return (_jsxs("div", { ref: containerRef, className: jc('relative flex w-full cursor-pointer flex-col gap-[2px] outline-none', isOpen && 'z-[1001]'), onClick: handleToggle, onKeyDown: handleKeyDown, tabIndex: disabled ? -1 : 0, children: [label && (_jsx(Offset, { className: "pr-10", children: _jsx(Typo, { size: 's', color: 'secondary', weight: '500', children: label }) })), _jsxs("div", { className: "relative w-full", children: [_jsxs("div", { className: jc('flex min-h-[36px] w-full items-center justify-between rounded bg-background-accent transition-all duration-200 pr-10'), children: [isOpen ? (_jsx(Input, { size: 'l', autoFocus: true, placeholder: selectedOption?.label || placeholder, value: search, onChange: (e) => {
|
|
71
|
+
setSearch(e.target.value);
|
|
72
|
+
setActiveIndex(-1);
|
|
73
|
+
}, onClick: (e) => e.stopPropagation() })) : (_jsx(Offset, { children: _jsx(Typo, { size: 'l', color: selectedOption?.label ? 'default' : 'secondary', weight: '500', children: selectedOption?.label || placeholder }) })), _jsx(ChevronDown, { size: 16, className: jc('opacity-0 transition-transform duration-200', isOpen ? 'rotate-180' : undefined) })] }), _jsx("div", { className: "absolute right-3 flex items-center h-full top-0 pointer-events-none", children: _jsx(ChevronDown, { size: 16, className: jc('opacity-50 transition-transform duration-200', isOpen ? 'rotate-180' : undefined) }) }), _jsx(Dropdown, { isOpen: isOpen, onClose: () => {
|
|
74
|
+
setIsOpen(false);
|
|
75
|
+
setActiveIndex(-1);
|
|
76
|
+
}, anchorRef: containerRef, children: filteredOptions.length > 0 ? (_jsx(Flex, { direction: 'column', gap: '4px', children: filteredOptions.map((option, index) => (_jsx(Cell, { active: index === activeIndex, onClick: (e) => {
|
|
77
|
+
e.stopPropagation();
|
|
78
|
+
handleSelect(option);
|
|
79
|
+
}, title: _jsx(Typo, { size: 'l', color: 'secondary', children: option.label }) }, option.label))) })) : (_jsx("div", { className: "px-4 py-2 text-[12px] text-secondary-foreground", children: "No options found" })) })] })] }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { Select } from './select';
|
|
3
|
+
declare const meta: Meta<typeof Select>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithoutLabel: Story;
|
|
8
|
+
export declare const Disabled: Story;
|