@lism-css/ui 0.10.0 → 0.12.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/README.md +1 -1
- package/dist/components/Accordion/Accordion.stories.d.ts +7 -0
- package/dist/components/Accordion/getProps.d.ts +55 -42
- package/dist/components/Accordion/getProps.js +36 -32
- package/dist/components/Accordion/react/AccIcon.d.ts +2 -1
- package/dist/components/Accordion/react/Accordion.d.ts +12 -21
- package/dist/components/Accordion/react/Accordion.js +30 -29
- package/dist/components/Accordion/react/index.d.ts +10 -11
- package/dist/components/Accordion/setAccordion.d.ts +6 -3
- package/dist/components/Accordion/setAccordion.js +12 -10
- package/dist/components/Alert/Alert.stories.d.ts +13 -0
- package/dist/components/Alert/getProps.d.ts +6 -4
- package/dist/components/Alert/react/Alert.d.ts +3 -4
- package/dist/components/Alert/react/Alert.js +2 -2
- package/dist/components/Avatar/Avatar.stories.d.ts +8 -0
- package/dist/components/Avatar/react/Avatar.d.ts +10 -6
- package/dist/components/Avatar/react/Avatar.js +1 -1
- package/dist/components/Badge/Badge.stories.d.ts +8 -0
- package/dist/components/Badge/react/Badge.d.ts +3 -1
- package/dist/components/Badge/react/Badge.js +5 -8
- package/dist/components/Button/Button.stories.d.ts +8 -0
- package/dist/components/Button/react/Button.d.ts +3 -1
- package/dist/components/Button/react/Button.js +3 -6
- package/dist/components/Callout/Callout.stories.d.ts +12 -0
- package/dist/components/Callout/getProps.d.ts +3 -3
- package/dist/components/Callout/getProps.js +11 -12
- package/dist/components/Callout/react/Callout.d.ts +3 -4
- package/dist/components/Callout/react/Callout.js +4 -4
- package/dist/components/Chat/Chat.stories.d.ts +9 -0
- package/dist/components/Chat/getProps.d.ts +43 -44
- package/dist/components/Chat/getProps.js +2 -2
- package/dist/components/Chat/react/Chat.d.ts +11 -7
- package/dist/components/Chat/react/Chat.js +10 -10
- package/dist/components/Details/Details.stories.d.ts +6 -0
- package/dist/components/Details/getProps.d.ts +34 -35
- package/dist/components/Details/getProps.js +16 -6
- package/dist/components/Details/react/Details.d.ts +11 -20
- package/dist/components/Details/react/Details.js +15 -15
- package/dist/components/Details/react/index.d.ts +7 -7
- package/dist/components/DummyImage/DummyImage.stories.d.ts +7 -0
- package/dist/components/DummyText/DummyText.stories.d.ts +9 -0
- package/dist/components/Modal/Modal.stories.d.ts +6 -0
- package/dist/components/Modal/getProps.d.ts +36 -36
- package/dist/components/Modal/getProps.js +36 -17
- package/dist/components/Modal/react/Body.d.ts +2 -4
- package/dist/components/Modal/react/CloseBtn.d.ts +9 -7
- package/dist/components/Modal/react/CloseBtn.js +5 -5
- package/dist/components/Modal/react/Inner.d.ts +3 -4
- package/dist/components/Modal/react/Modal.d.ts +4 -4
- package/dist/components/Modal/react/Modal.js +11 -9
- package/dist/components/Modal/react/OpenBtn.d.ts +7 -5
- package/dist/components/Modal/react/OpenBtn.js +4 -4
- package/dist/components/Modal/react/index.d.ts +7 -8
- package/dist/components/NavMenu/NavMenu.stories.d.ts +7 -0
- package/dist/components/NavMenu/getProps.d.ts +31 -29
- package/dist/components/NavMenu/react/NavMenu.d.ts +6 -16
- package/dist/components/NavMenu/react/NavMenu.js +21 -17
- package/dist/components/NavMenu/react/index.d.ts +6 -6
- package/dist/components/ShapeDivider/ShapeDivider.stories.d.ts +10 -0
- package/dist/components/ShapeDivider/getProps.d.ts +16 -11
- package/dist/components/ShapeDivider/getProps.js +10 -12
- package/dist/components/ShapeDivider/react/ShapeDivider.d.ts +3 -4
- package/dist/components/ShapeDivider/react/ShapeDivider.js +3 -3
- package/dist/components/Tabs/Tabs.stories.d.ts +6 -0
- package/dist/components/Tabs/getProps.d.ts +11 -4
- package/dist/components/Tabs/getProps.js +14 -4
- package/dist/components/Tabs/react/Tab.d.ts +8 -6
- package/dist/components/Tabs/react/Tab.js +15 -6
- package/dist/components/Tabs/react/TabItem.d.ts +7 -4
- package/dist/components/Tabs/react/TabList.d.ts +2 -1
- package/dist/components/Tabs/react/TabPanel.d.ts +8 -6
- package/dist/components/Tabs/react/Tabs.d.ts +9 -7
- package/dist/components/Tabs/react/Tabs.js +50 -36
- package/dist/components/Tabs/react/index.d.ts +8 -8
- package/dist/components/Tabs/setTabs.d.ts +1 -1
- package/dist/components/Tabs/setTabs.js +25 -15
- package/dist/lism-css/dist/components/{Center → layout/Center}/index.js +1 -1
- package/dist/lism-css/dist/components/{Flex → layout/Flex}/index.js +1 -1
- package/dist/lism-css/dist/components/{Flow → layout/Flow}/index.js +1 -1
- package/dist/lism-css/dist/components/{Frame → layout/Frame}/index.js +1 -1
- package/dist/lism-css/dist/components/{Grid → layout/Grid}/index.js +1 -1
- package/dist/lism-css/dist/components/{Stack → layout/Stack}/index.js +1 -1
- package/dist/lism-css/dist/config/defaults/props.js +16 -26
- package/dist/lism-css/dist/config/defaults/states.js +3 -24
- package/dist/lism-css/dist/config/defaults/tokens.js +2 -2
- package/dist/lism-css/dist/lib/getLayoutProps.js +6 -9
- package/dist/lism-css/dist/lib/getLismProps.js +94 -92
- package/dist/lism-css/dist/lib/helper/mergeSet.js +14 -0
- package/dist/style.css +1 -1
- package/dist/ui.css +1 -1
- package/package.json +14 -7
- package/src/components/Accordion/Accordion.stories.tsx +105 -0
- package/src/components/Accordion/astro/Button.astro +2 -2
- package/src/components/Accordion/getProps.ts +91 -0
- package/src/components/Accordion/react/{AccIcon.jsx → AccIcon.tsx} +2 -2
- package/src/components/Accordion/react/{Accordion.jsx → Accordion.tsx} +33 -11
- package/src/components/Accordion/setAccordion.ts +120 -0
- package/src/components/Alert/Alert.stories.tsx +64 -0
- package/src/components/Alert/getProps.ts +5 -3
- package/src/components/Alert/react/Alert.tsx +3 -3
- package/src/components/Avatar/Avatar.stories.tsx +42 -0
- package/src/components/Avatar/react/Avatar.tsx +17 -0
- package/src/components/Badge/Badge.stories.tsx +40 -0
- package/src/components/Badge/astro/Badge.astro +1 -7
- package/src/components/Badge/react/Badge.tsx +7 -0
- package/src/components/Button/Button.stories.tsx +44 -0
- package/src/components/Button/astro/Button.astro +1 -7
- package/src/components/Button/react/Button.tsx +7 -0
- package/src/components/Callout/Callout.stories.tsx +55 -0
- package/src/components/Callout/getProps.ts +5 -5
- package/src/components/Callout/react/Callout.tsx +3 -3
- package/src/components/Chat/Chat.stories.tsx +58 -0
- package/src/components/Chat/_style.css +5 -5
- package/src/components/Chat/{getProps.js → getProps.ts} +10 -4
- package/src/components/Chat/react/{Chat.jsx → Chat.tsx} +13 -3
- package/src/components/Details/Details.stories.tsx +61 -0
- package/src/components/Details/astro/Title.astro +2 -2
- package/src/components/Details/{getProps.js → getProps.ts} +19 -6
- package/src/components/Details/react/Details.tsx +69 -0
- package/src/components/DummyImage/DummyImage.stories.tsx +23 -0
- package/src/components/DummyText/DummyText.stories.tsx +48 -0
- package/src/components/Modal/Modal.stories.tsx +67 -0
- package/src/components/Modal/astro/CloseBtn.astro +2 -2
- package/src/components/Modal/astro/OpenBtn.astro +2 -3
- package/src/components/Modal/getProps.ts +65 -0
- package/src/components/Modal/react/Body.tsx +10 -0
- package/src/components/Modal/react/CloseBtn.tsx +24 -0
- package/src/components/Modal/react/Inner.tsx +6 -0
- package/src/components/Modal/react/Modal.tsx +24 -0
- package/src/components/Modal/react/OpenBtn.tsx +15 -0
- package/src/components/Modal/{script.js → script.ts} +1 -1
- package/src/components/NavMenu/NavMenu.stories.tsx +68 -0
- package/src/components/NavMenu/getProps.ts +60 -0
- package/src/components/NavMenu/react/NavMenu.tsx +40 -0
- package/src/components/ShapeDivider/ShapeDivider.stories.tsx +87 -0
- package/src/components/ShapeDivider/getProps.ts +36 -0
- package/src/components/ShapeDivider/react/{ShapeDivider.jsx → ShapeDivider.tsx} +4 -4
- package/src/components/Tabs/Tabs.stories.tsx +79 -0
- package/src/components/Tabs/astro/Tab.astro +2 -1
- package/src/components/Tabs/astro/{transformTabitems.js → transformTabitems.ts} +9 -9
- package/src/components/Tabs/getProps.ts +23 -0
- package/src/components/Tabs/react/Tab.tsx +21 -0
- package/src/components/Tabs/react/TabItem.tsx +13 -0
- package/src/components/Tabs/react/TabList.tsx +5 -0
- package/src/components/Tabs/react/{TabPanel.jsx → TabPanel.tsx} +8 -3
- package/src/components/Tabs/react/{Tabs.jsx → Tabs.tsx} +27 -12
- package/src/components/Tabs/{script.js → script.ts} +2 -2
- package/src/components/Tabs/setTabs.ts +65 -0
- package/src/helper/{uuid.js → uuid.ts} +2 -2
- package/src/vite-env.d.ts +1 -0
- package/dist/components/Accordion/astro/__setEvent.d.ts +0 -1
- package/dist/components/Accordion/astro/index.d.ts +0 -15
- package/dist/components/Alert/astro/index.d.ts +0 -1
- package/dist/components/Callout/astro/index.d.ts +0 -1
- package/dist/components/Details/astro/index.d.ts +0 -13
- package/dist/components/DummyImage/astro/index.d.ts +0 -1
- package/dist/components/DummyText/astro/index.d.ts +0 -1
- package/dist/components/Modal/astro/index.d.ts +0 -13
- package/dist/components/NavMenu/astro/index.d.ts +0 -11
- package/dist/components/Tabs/astro/index.d.ts +0 -13
- package/dist/components/Tabs/astro/transformTabitems.d.ts +0 -4
- package/dist/components/astro.d.ts +0 -14
- package/dist/lism-css/dist/config/helper/getSvgUrl.js +0 -4
- package/src/components/Accordion/getProps.js +0 -77
- package/src/components/Accordion/setAccordion.js +0 -146
- package/src/components/Avatar/astro/index.js +0 -1
- package/src/components/Avatar/react/Avatar.jsx +0 -9
- package/src/components/Badge/astro/index.js +0 -1
- package/src/components/Badge/react/Badge.jsx +0 -12
- package/src/components/Button/astro/index.js +0 -1
- package/src/components/Button/react/Button.jsx +0 -12
- package/src/components/Chat/astro/index.js +0 -1
- package/src/components/Details/react/Details.jsx +0 -66
- package/src/components/Modal/getProps.js +0 -30
- package/src/components/Modal/react/Body.jsx +0 -10
- package/src/components/Modal/react/CloseBtn.jsx +0 -20
- package/src/components/Modal/react/Inner.jsx +0 -6
- package/src/components/Modal/react/Modal.jsx +0 -23
- package/src/components/Modal/react/OpenBtn.jsx +0 -11
- package/src/components/NavMenu/getProps.js +0 -65
- package/src/components/NavMenu/react/NavMenu.jsx +0 -19
- package/src/components/ShapeDivider/astro/index.js +0 -1
- package/src/components/ShapeDivider/getProps.js +0 -40
- package/src/components/Tabs/getProps.js +0 -8
- package/src/components/Tabs/react/Tab.jsx +0 -10
- package/src/components/Tabs/react/TabItem.jsx +0 -5
- package/src/components/Tabs/react/TabList.jsx +0 -6
- package/src/components/Tabs/setTabs.js +0 -87
- /package/src/components/Accordion/astro/{index.js → index.ts} +0 -0
- /package/src/components/Accordion/react/{index.js → index.ts} +0 -0
- /package/src/components/Accordion/{script.js → script.ts} +0 -0
- /package/{dist/components/Avatar/astro/index.d.ts → src/components/Avatar/astro/index.ts} +0 -0
- /package/src/components/Avatar/react/{index.js → index.ts} +0 -0
- /package/{dist/components/Badge/astro/index.d.ts → src/components/Badge/astro/index.ts} +0 -0
- /package/src/components/Badge/react/{index.js → index.ts} +0 -0
- /package/{dist/components/Button/astro/index.d.ts → src/components/Button/astro/index.ts} +0 -0
- /package/src/components/Button/react/{index.js → index.ts} +0 -0
- /package/{dist/components/Chat/astro/index.d.ts → src/components/Chat/astro/index.ts} +0 -0
- /package/src/components/Chat/react/{index.js → index.ts} +0 -0
- /package/src/components/Details/astro/{index.js → index.ts} +0 -0
- /package/src/components/Details/react/{index.js → index.ts} +0 -0
- /package/src/components/Modal/astro/{index.js → index.ts} +0 -0
- /package/src/components/Modal/react/{index.js → index.ts} +0 -0
- /package/src/components/NavMenu/astro/{index.js → index.ts} +0 -0
- /package/src/components/NavMenu/react/{index.js → index.ts} +0 -0
- /package/{dist/components/ShapeDivider/astro/index.d.ts → src/components/ShapeDivider/astro/index.ts} +0 -0
- /package/src/components/ShapeDivider/react/{index.js → index.ts} +0 -0
- /package/src/components/Tabs/astro/{index.js → index.ts} +0 -0
- /package/src/components/Tabs/react/{index.js → index.ts} +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import NavMenu from './react';
|
|
3
|
+
|
|
4
|
+
const meta: Meta = {
|
|
5
|
+
title: 'UI/NavMenu',
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj;
|
|
11
|
+
|
|
12
|
+
export const Default: Story = {
|
|
13
|
+
render: () => (
|
|
14
|
+
<NavMenu.Root>
|
|
15
|
+
<NavMenu.Item>
|
|
16
|
+
<NavMenu.Link href="#">ホーム</NavMenu.Link>
|
|
17
|
+
</NavMenu.Item>
|
|
18
|
+
<NavMenu.Item>
|
|
19
|
+
<NavMenu.Link href="#">ブログ</NavMenu.Link>
|
|
20
|
+
</NavMenu.Item>
|
|
21
|
+
<NavMenu.Item>
|
|
22
|
+
<NavMenu.Link href="#">お問い合わせ</NavMenu.Link>
|
|
23
|
+
</NavMenu.Item>
|
|
24
|
+
</NavMenu.Root>
|
|
25
|
+
),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const WithNest: Story = {
|
|
29
|
+
name: 'ネスト(サブメニュー)付き',
|
|
30
|
+
render: () => (
|
|
31
|
+
<NavMenu.Root>
|
|
32
|
+
<NavMenu.Item>
|
|
33
|
+
<NavMenu.Link href="#">ホーム</NavMenu.Link>
|
|
34
|
+
</NavMenu.Item>
|
|
35
|
+
<NavMenu.Item>
|
|
36
|
+
<NavMenu.Link>サービス</NavMenu.Link>
|
|
37
|
+
<NavMenu.Nest>
|
|
38
|
+
<NavMenu.Item>
|
|
39
|
+
<NavMenu.Link href="#">サービス A</NavMenu.Link>
|
|
40
|
+
</NavMenu.Item>
|
|
41
|
+
<NavMenu.Item>
|
|
42
|
+
<NavMenu.Link href="#">サービス B</NavMenu.Link>
|
|
43
|
+
</NavMenu.Item>
|
|
44
|
+
</NavMenu.Nest>
|
|
45
|
+
</NavMenu.Item>
|
|
46
|
+
<NavMenu.Item>
|
|
47
|
+
<NavMenu.Link href="#">お問い合わせ</NavMenu.Link>
|
|
48
|
+
</NavMenu.Item>
|
|
49
|
+
</NavMenu.Root>
|
|
50
|
+
),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const WithHoverColor: Story = {
|
|
54
|
+
name: 'ホバーカラー指定',
|
|
55
|
+
render: () => (
|
|
56
|
+
<NavMenu.Root hovBgc="base-2" itemP="10">
|
|
57
|
+
<NavMenu.Item>
|
|
58
|
+
<NavMenu.Link href="#">ホーム</NavMenu.Link>
|
|
59
|
+
</NavMenu.Item>
|
|
60
|
+
<NavMenu.Item>
|
|
61
|
+
<NavMenu.Link href="#">ブログ</NavMenu.Link>
|
|
62
|
+
</NavMenu.Item>
|
|
63
|
+
<NavMenu.Item>
|
|
64
|
+
<NavMenu.Link href="#">お問い合わせ</NavMenu.Link>
|
|
65
|
+
</NavMenu.Item>
|
|
66
|
+
</NavMenu.Root>
|
|
67
|
+
),
|
|
68
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NavMenu コンポーネントの共通プロパティ処理
|
|
3
|
+
*/
|
|
4
|
+
import getMaybeCssVar from 'lism-css/lib/getMaybeCssVar';
|
|
5
|
+
|
|
6
|
+
export type NavMenuRootProps = {
|
|
7
|
+
hovC?: string;
|
|
8
|
+
hovBgc?: string;
|
|
9
|
+
itemP?: string;
|
|
10
|
+
style?: Record<string, string>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type NavMenuLinkProps = {
|
|
15
|
+
href?: string;
|
|
16
|
+
as?: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function getRootProps({ hovC, hovBgc, itemP, style = {}, ...props }: NavMenuRootProps) {
|
|
21
|
+
const computedStyle = { ...style };
|
|
22
|
+
|
|
23
|
+
if (hovBgc) computedStyle['--hov-bgc'] = getMaybeCssVar(hovBgc, 'color');
|
|
24
|
+
if (hovC) computedStyle['--hov-c'] = getMaybeCssVar(hovC, 'color');
|
|
25
|
+
if (itemP) computedStyle['--_item-p'] = getMaybeCssVar(itemP, 'space');
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
lismClass: 'c--navMenu',
|
|
29
|
+
as: 'ul',
|
|
30
|
+
style: computedStyle,
|
|
31
|
+
...props,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getNestProps(props: Record<string, unknown>) {
|
|
36
|
+
return {
|
|
37
|
+
lismClass: 'c--navMenu_nest',
|
|
38
|
+
as: 'ul',
|
|
39
|
+
'px-s': '20',
|
|
40
|
+
...props,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getItemProps(props: Record<string, unknown>) {
|
|
45
|
+
return {
|
|
46
|
+
lismClass: 'c--navMenu_item',
|
|
47
|
+
as: 'li',
|
|
48
|
+
...props,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getLinkProps({ href, as = 'span', ...props }: NavMenuLinkProps) {
|
|
53
|
+
return {
|
|
54
|
+
lismClass: 'c--navMenu_link',
|
|
55
|
+
as: href ? 'a' : as,
|
|
56
|
+
href,
|
|
57
|
+
c: 'inherit',
|
|
58
|
+
...props,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ElementType } from 'react';
|
|
2
|
+
import { Lism, Stack, Flex, type LismComponentProps } from 'lism-css/react';
|
|
3
|
+
import { getRootProps, getNestProps, getItemProps, getLinkProps, type NavMenuRootProps, type NavMenuLinkProps } from '../getProps';
|
|
4
|
+
import '../_style.css';
|
|
5
|
+
|
|
6
|
+
export function Root({ children, ...props }: NavMenuRootProps & LismComponentProps) {
|
|
7
|
+
const { as: rootAs, ...rootProps } = getRootProps(props);
|
|
8
|
+
return (
|
|
9
|
+
<Stack as={rootAs as ElementType} {...rootProps}>
|
|
10
|
+
{children}
|
|
11
|
+
</Stack>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Nest({ children, ...props }: LismComponentProps) {
|
|
16
|
+
const { as: nestAs, ...nestProps } = getNestProps(props);
|
|
17
|
+
return (
|
|
18
|
+
<Stack as={nestAs as ElementType} {...nestProps}>
|
|
19
|
+
{children}
|
|
20
|
+
</Stack>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Item({ children, ...props }: LismComponentProps) {
|
|
25
|
+
const { as: itemAs, ...itemProps } = getItemProps(props);
|
|
26
|
+
return (
|
|
27
|
+
<Lism as={itemAs as ElementType} {...itemProps}>
|
|
28
|
+
{children}
|
|
29
|
+
</Lism>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Link({ children, ...props }: NavMenuLinkProps & LismComponentProps) {
|
|
34
|
+
const { as: linkAs, ...linkProps } = getLinkProps(props);
|
|
35
|
+
return (
|
|
36
|
+
<Flex as={linkAs as ElementType} {...linkProps}>
|
|
37
|
+
{children}
|
|
38
|
+
</Flex>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import ShapeDivider from './react/ShapeDivider';
|
|
3
|
+
|
|
4
|
+
const WAVE_PATH =
|
|
5
|
+
'M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof ShapeDivider> = {
|
|
8
|
+
title: 'UI/ShapeDivider',
|
|
9
|
+
component: ShapeDivider,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
argTypes: {
|
|
12
|
+
children: { control: false },
|
|
13
|
+
level: { control: 'number' },
|
|
14
|
+
flip: { control: 'select', options: [undefined, 'X', 'Y', 'XY'] },
|
|
15
|
+
isAnimation: { control: 'boolean' },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof ShapeDivider>;
|
|
21
|
+
|
|
22
|
+
export const Default: Story = {
|
|
23
|
+
args: {
|
|
24
|
+
viewBox: '0 0 1200 120',
|
|
25
|
+
level: 5,
|
|
26
|
+
},
|
|
27
|
+
render: (args) => (
|
|
28
|
+
<ShapeDivider {...args}>
|
|
29
|
+
<path d={WAVE_PATH} />
|
|
30
|
+
</ShapeDivider>
|
|
31
|
+
),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const FlipX: Story = {
|
|
35
|
+
name: 'flip: X(左右反転)',
|
|
36
|
+
args: {
|
|
37
|
+
viewBox: '0 0 1200 120',
|
|
38
|
+
level: 5,
|
|
39
|
+
flip: 'X',
|
|
40
|
+
},
|
|
41
|
+
render: (args) => (
|
|
42
|
+
<ShapeDivider {...args}>
|
|
43
|
+
<path d={WAVE_PATH} />
|
|
44
|
+
</ShapeDivider>
|
|
45
|
+
),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const FlipY: Story = {
|
|
49
|
+
name: 'flip: Y(上下反転)',
|
|
50
|
+
args: {
|
|
51
|
+
viewBox: '0 0 1200 120',
|
|
52
|
+
level: 5,
|
|
53
|
+
flip: 'Y',
|
|
54
|
+
},
|
|
55
|
+
render: (args) => (
|
|
56
|
+
<ShapeDivider {...args}>
|
|
57
|
+
<path d={WAVE_PATH} />
|
|
58
|
+
</ShapeDivider>
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const HighLevel: Story = {
|
|
63
|
+
name: 'level: 10',
|
|
64
|
+
args: {
|
|
65
|
+
viewBox: '0 0 1200 120',
|
|
66
|
+
level: 10,
|
|
67
|
+
},
|
|
68
|
+
render: (args) => (
|
|
69
|
+
<ShapeDivider {...args}>
|
|
70
|
+
<path d={WAVE_PATH} />
|
|
71
|
+
</ShapeDivider>
|
|
72
|
+
),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const Animation: Story = {
|
|
76
|
+
name: 'animation',
|
|
77
|
+
args: {
|
|
78
|
+
viewBox: '0 0 1200 120',
|
|
79
|
+
level: 10,
|
|
80
|
+
isAnimation: true,
|
|
81
|
+
},
|
|
82
|
+
render: (args) => (
|
|
83
|
+
<ShapeDivider {...args}>
|
|
84
|
+
<path d={WAVE_PATH} />
|
|
85
|
+
</ShapeDivider>
|
|
86
|
+
),
|
|
87
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type ShapeDividerProps = {
|
|
2
|
+
viewBox?: string;
|
|
3
|
+
isAnimation?: boolean;
|
|
4
|
+
isEmpty?: boolean;
|
|
5
|
+
level?: number;
|
|
6
|
+
stretch?: string;
|
|
7
|
+
offset?: string;
|
|
8
|
+
flip?: string;
|
|
9
|
+
style?: Record<string, string>;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default function getProps({ viewBox, isAnimation, isEmpty, level = 5, stretch, offset, flip, style = {}, ...restProps }: ShapeDividerProps) {
|
|
14
|
+
if (level === 0) return null;
|
|
15
|
+
|
|
16
|
+
const computedStyle: Record<string, string | undefined> = { ...style };
|
|
17
|
+
computedStyle['--level'] = level != null ? String(level) : undefined;
|
|
18
|
+
computedStyle['--_inner-offset'] = offset ?? undefined;
|
|
19
|
+
computedStyle['--_inner-stretch'] = stretch ?? undefined;
|
|
20
|
+
|
|
21
|
+
const _props: Record<string, unknown> = {
|
|
22
|
+
lismClass: 'c--shapeDivider',
|
|
23
|
+
'max-sz': 'full',
|
|
24
|
+
'aria-hidden': 'true',
|
|
25
|
+
};
|
|
26
|
+
if (flip) _props['data-flip'] = flip;
|
|
27
|
+
if (isAnimation) _props['data-has-animation'] = 'true';
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
..._props,
|
|
31
|
+
style: computedStyle,
|
|
32
|
+
viewBox,
|
|
33
|
+
isEmpty,
|
|
34
|
+
...restProps,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Lism } from 'lism-css/react';
|
|
2
|
-
import getProps from '../getProps';
|
|
1
|
+
import { Lism, type LismComponentProps } from 'lism-css/react';
|
|
2
|
+
import getProps, { type ShapeDividerProps } from '../getProps';
|
|
3
3
|
import '../_style.css';
|
|
4
4
|
|
|
5
|
-
export default function ShapeDivider({ children, ...props }) {
|
|
5
|
+
export default function ShapeDivider({ children, ...props }: ShapeDividerProps & LismComponentProps) {
|
|
6
6
|
const componentProps = getProps(props);
|
|
7
7
|
|
|
8
8
|
// level が 0 の場合は非表示
|
|
9
9
|
if (!componentProps) return null;
|
|
10
10
|
|
|
11
|
-
const { viewBox,
|
|
11
|
+
const { viewBox, isEmpty, ...lismProps } = componentProps;
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
14
|
<Lism {...lismProps}>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
3
|
+
import Tabs from './react';
|
|
4
|
+
|
|
5
|
+
const meta: Meta = {
|
|
6
|
+
title: 'UI/Tabs',
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default meta;
|
|
11
|
+
type Story = StoryObj;
|
|
12
|
+
|
|
13
|
+
export const Default: Story = {
|
|
14
|
+
render: () => (
|
|
15
|
+
<Tabs.Root>
|
|
16
|
+
<Tabs.Item>
|
|
17
|
+
<Tabs.Tab>タブ 1</Tabs.Tab>
|
|
18
|
+
<Tabs.Panel>タブ 1 のコンテンツです。</Tabs.Panel>
|
|
19
|
+
</Tabs.Item>
|
|
20
|
+
<Tabs.Item>
|
|
21
|
+
<Tabs.Tab>タブ 2</Tabs.Tab>
|
|
22
|
+
<Tabs.Panel>タブ 2 のコンテンツです。</Tabs.Panel>
|
|
23
|
+
</Tabs.Item>
|
|
24
|
+
<Tabs.Item>
|
|
25
|
+
<Tabs.Tab>タブ 3</Tabs.Tab>
|
|
26
|
+
<Tabs.Panel>タブ 3 のコンテンツです。</Tabs.Panel>
|
|
27
|
+
</Tabs.Item>
|
|
28
|
+
</Tabs.Root>
|
|
29
|
+
),
|
|
30
|
+
play: async ({ canvasElement }) => {
|
|
31
|
+
const canvas = within(canvasElement);
|
|
32
|
+
const tabs = canvas.getAllByRole('tab');
|
|
33
|
+
const [tab1, tab2, tab3] = tabs;
|
|
34
|
+
|
|
35
|
+
// 初期状態: タブ 1 が選択されている
|
|
36
|
+
await expect(tab1).toHaveAttribute('aria-selected', 'true');
|
|
37
|
+
await expect(tab2).toHaveAttribute('aria-selected', 'false');
|
|
38
|
+
await expect(tab3).toHaveAttribute('aria-selected', 'false');
|
|
39
|
+
|
|
40
|
+
// タブ 2 をクリック
|
|
41
|
+
await userEvent.click(tab2);
|
|
42
|
+
await expect(tab1).toHaveAttribute('aria-selected', 'false');
|
|
43
|
+
await expect(tab2).toHaveAttribute('aria-selected', 'true');
|
|
44
|
+
|
|
45
|
+
// タブ 3 をクリック
|
|
46
|
+
await userEvent.click(tab3);
|
|
47
|
+
await expect(tab2).toHaveAttribute('aria-selected', 'false');
|
|
48
|
+
await expect(tab3).toHaveAttribute('aria-selected', 'true');
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const DefaultIndex2: Story = {
|
|
53
|
+
name: 'defaultIndex: 2(2番目をデフォルト選択)',
|
|
54
|
+
render: () => (
|
|
55
|
+
<Tabs.Root defaultIndex={2}>
|
|
56
|
+
<Tabs.Item>
|
|
57
|
+
<Tabs.Tab>タブ 1</Tabs.Tab>
|
|
58
|
+
<Tabs.Panel>タブ 1 のコンテンツです。</Tabs.Panel>
|
|
59
|
+
</Tabs.Item>
|
|
60
|
+
<Tabs.Item>
|
|
61
|
+
<Tabs.Tab>タブ 2</Tabs.Tab>
|
|
62
|
+
<Tabs.Panel>タブ 2 がデフォルトで選択されています。</Tabs.Panel>
|
|
63
|
+
</Tabs.Item>
|
|
64
|
+
<Tabs.Item>
|
|
65
|
+
<Tabs.Tab>タブ 3</Tabs.Tab>
|
|
66
|
+
<Tabs.Panel>タブ 3 のコンテンツです。</Tabs.Panel>
|
|
67
|
+
</Tabs.Item>
|
|
68
|
+
</Tabs.Root>
|
|
69
|
+
),
|
|
70
|
+
play: async ({ canvasElement }) => {
|
|
71
|
+
const canvas = within(canvasElement);
|
|
72
|
+
const tabs = canvas.getAllByRole('tab');
|
|
73
|
+
const [tab1, tab2] = tabs;
|
|
74
|
+
|
|
75
|
+
// 初期状態: タブ 2 が選択されている
|
|
76
|
+
await expect(tab1).toHaveAttribute('aria-selected', 'false');
|
|
77
|
+
await expect(tab2).toHaveAttribute('aria-selected', 'true');
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
// import type { LismProps } from 'lism-css/types';
|
|
3
3
|
import { Lism } from 'lism-css/astro';
|
|
4
|
+
import { getTabProps } from '../getProps';
|
|
4
5
|
|
|
5
6
|
// export interface Props extends LismProps {
|
|
6
7
|
// // controlId: string;
|
|
@@ -12,6 +13,6 @@ const { tabId = 'tab', index = 0, isActive, ...props } = Astro.props;
|
|
|
12
13
|
const controlId = `${tabId}-${index}`;
|
|
13
14
|
---
|
|
14
15
|
|
|
15
|
-
<Lism
|
|
16
|
+
<Lism {...getTabProps(props)} role="tab" aria-controls={controlId} aria-selected={isActive ? 'true' : 'false'}>
|
|
16
17
|
<slot />
|
|
17
18
|
</Lism>
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
+
type TransformResult = {
|
|
2
|
+
btns: string[];
|
|
3
|
+
panels: string[];
|
|
4
|
+
};
|
|
5
|
+
|
|
1
6
|
// <lism-placeholder-tabitem> → div.tabitem へ 変換
|
|
2
|
-
export default function transformHTML(htmlString, tabID, defaultIndex) {
|
|
7
|
+
export default function transformHTML(htmlString: string, tabID: string, defaultIndex: number): TransformResult {
|
|
3
8
|
let index = 1; // 1スタート
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
const btns: string[] = [];
|
|
10
|
+
const panels: string[] = [];
|
|
6
11
|
|
|
7
|
-
// <lism-placeholder-tabitem>でコンテンツを囲んでいるので中身を解析する。
|
|
8
12
|
const regex = /<lism-placeholder-tabitem(.*?)>(.*?)<\/lism-placeholder-tabitem>/gs;
|
|
9
13
|
const matches = [...htmlString.matchAll(regex)];
|
|
10
14
|
|
|
11
|
-
// console.log(matches);
|
|
12
15
|
matches.forEach((match) => {
|
|
13
|
-
// const tabItemAttrs = match[1]; // 使わないがdata-astro-source-file属性が自動でついてきたりするので、属性値があっても問題ないようにしている。
|
|
14
16
|
const tabItemContent = match[2];
|
|
15
17
|
|
|
16
18
|
const controlId = `${tabID}-${index}`;
|
|
17
19
|
const isActive = index === defaultIndex;
|
|
18
20
|
index++;
|
|
19
21
|
|
|
20
|
-
// <lism-placeholder-tabtbn>からタブボタンを生成
|
|
21
22
|
const btnMatch = tabItemContent.match(/<button(.*?)>(.*?)<\/button>(.*)/s);
|
|
22
23
|
if (!btnMatch) return;
|
|
23
24
|
let btnAtts = btnMatch[1];
|
|
24
|
-
|
|
25
|
+
const btnContent = btnMatch[2];
|
|
25
26
|
let panel = btnMatch[3];
|
|
26
27
|
|
|
27
|
-
// btnContent = btnContent.replace(` slot="tab"`, '');
|
|
28
28
|
btnAtts = btnAtts.replace(`aria-controls="tab-0"`, `aria-controls="${controlId}"`);
|
|
29
29
|
panel = panel.replace(`id="tab-0"`, `id="${controlId}"`);
|
|
30
30
|
if (isActive) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import atts from 'lism-css/lib/helper/atts';
|
|
2
|
+
import mergeSet from 'lism-css/lib/helper/mergeSet';
|
|
3
|
+
|
|
4
|
+
type TabsProps = {
|
|
5
|
+
lismClass?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default function getTabsProps({ lismClass, ...props }: TabsProps) {
|
|
10
|
+
return {
|
|
11
|
+
lismClass: atts(lismClass, 'c--tabs'),
|
|
12
|
+
...props,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getTabProps({ set, unset, ...props }: Record<string, unknown>) {
|
|
17
|
+
return {
|
|
18
|
+
as: 'button',
|
|
19
|
+
lismClass: 'c--tabs_tab',
|
|
20
|
+
set: mergeSet('plain', set, unset),
|
|
21
|
+
...props,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Lism, type LismComponentProps } from 'lism-css/react';
|
|
2
|
+
import { getTabProps } from '../getProps';
|
|
3
|
+
|
|
4
|
+
type TabProps = LismComponentProps & {
|
|
5
|
+
tabId?: string;
|
|
6
|
+
index?: number;
|
|
7
|
+
isActive?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default function Tab({ tabId = 'tab', index = 0, isActive = false, ...props }: TabProps) {
|
|
11
|
+
const controlId = `${tabId}-${index}`;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<Lism
|
|
15
|
+
{...(getTabProps(props as Record<string, unknown>) as object)}
|
|
16
|
+
role="tab"
|
|
17
|
+
aria-controls={controlId}
|
|
18
|
+
aria-selected={isActive ? 'true' : 'false'}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type TabItemProps = {
|
|
4
|
+
isTabItem?: boolean;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Note: <Tabs>側でループして色々処理される。
|
|
9
|
+
// 引数でちゃんと処理したいpropを書いておかないとだめ。
|
|
10
|
+
export default function TabItem({ isTabItem = true, children }: TabItemProps) {
|
|
11
|
+
void isTabItem;
|
|
12
|
+
return <div>{children}</div>;
|
|
13
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import { Lism } from 'lism-css/react';
|
|
1
|
+
import { Lism, type LismComponentProps } from 'lism-css/react';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
type TabPanelProps = LismComponentProps & {
|
|
4
|
+
tabId?: string;
|
|
5
|
+
isActive?: boolean;
|
|
6
|
+
index?: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default function TabPanel({ tabId = 'tab', isActive = false, index = 0, ...props }: TabPanelProps) {
|
|
5
10
|
const controlId = `${tabId}-${index}`;
|
|
6
11
|
|
|
7
12
|
return <Lism id={controlId} role="tabpanel" aria-hidden={isActive ? 'false' : 'true'} lismClass="c--tabs_panel" {...props} />;
|
|
@@ -1,34 +1,41 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState, useId, Children, isValidElement } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import type { ElementType } from 'react';
|
|
4
|
+
import { Lism, type LismComponentProps } from 'lism-css/react';
|
|
4
5
|
import Tab from './Tab';
|
|
5
6
|
import TabItem from './TabItem';
|
|
6
7
|
import TabList from './TabList';
|
|
7
8
|
import TabPanel from './TabPanel';
|
|
8
9
|
import getTabsProps from '../getProps';
|
|
9
|
-
// import { TabContext } from './context';
|
|
10
10
|
|
|
11
11
|
import '../_style.css';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
type TabsProps<T extends ElementType = 'div'> = LismComponentProps<T> & {
|
|
14
|
+
tabId?: string;
|
|
15
|
+
defaultIndex?: number;
|
|
16
|
+
listProps?: LismComponentProps;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default function Tabs<T extends ElementType = 'div'>({ tabId = '', defaultIndex = 1, listProps = {}, children, ...props }: TabsProps<T>) {
|
|
14
20
|
const [activeIndex, setActiveIndex] = useState(defaultIndex);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
21
|
+
const generatedId = useId();
|
|
22
|
+
const theTabId = tabId || generatedId;
|
|
23
|
+
const btns: React.ReactElement[] = [];
|
|
24
|
+
const panels: React.ReactElement[] = [];
|
|
18
25
|
|
|
19
26
|
// Tabs.Item の処理
|
|
20
27
|
Children.forEach(children, (child, index) => {
|
|
21
28
|
const tabIndex = index + 1; // 1 はじまり
|
|
22
|
-
// console.log('child.type', isValidElement(child), child.type);
|
|
23
29
|
|
|
24
30
|
if (isValidElement(child) && child.type === TabItem) {
|
|
25
|
-
|
|
31
|
+
const childProps = child.props as { children?: React.ReactNode };
|
|
32
|
+
Children.forEach(childProps.children, (nestedChild) => {
|
|
26
33
|
if (isValidElement(nestedChild)) {
|
|
27
34
|
if (nestedChild.type === Tab) {
|
|
28
|
-
const tabProps = nestedChild.props
|
|
35
|
+
const tabProps = nestedChild.props as Record<string, unknown>;
|
|
29
36
|
btns.push(
|
|
30
37
|
<Tab
|
|
31
|
-
{...tabProps}
|
|
38
|
+
{...(tabProps as LismComponentProps)}
|
|
32
39
|
tabId={theTabId}
|
|
33
40
|
index={tabIndex}
|
|
34
41
|
key={tabIndex}
|
|
@@ -37,8 +44,16 @@ export default function Tabs({ tabId = '', defaultIndex = 1, listProps = {}, chi
|
|
|
37
44
|
/>
|
|
38
45
|
);
|
|
39
46
|
} else if (nestedChild.type === TabPanel) {
|
|
40
|
-
const panelProps = nestedChild.props
|
|
41
|
-
panels.push(
|
|
47
|
+
const panelProps = nestedChild.props as Record<string, unknown>;
|
|
48
|
+
panels.push(
|
|
49
|
+
<TabPanel
|
|
50
|
+
{...(panelProps as LismComponentProps)}
|
|
51
|
+
tabId={theTabId}
|
|
52
|
+
index={tabIndex}
|
|
53
|
+
key={tabIndex}
|
|
54
|
+
isActive={tabIndex === activeIndex}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
42
57
|
}
|
|
43
58
|
}
|
|
44
59
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import setTabs from './setTabs
|
|
1
|
+
import setTabs from './setTabs';
|
|
2
2
|
|
|
3
3
|
document.addEventListener('DOMContentLoaded', function () {
|
|
4
|
-
const tabsAll = document.querySelectorAll('.c--tabs');
|
|
4
|
+
const tabsAll = document.querySelectorAll<HTMLElement>('.c--tabs');
|
|
5
5
|
tabsAll.forEach((tabs) => {
|
|
6
6
|
setTabs(tabs);
|
|
7
7
|
});
|