@lism-css/ui 0.2.2 → 0.8.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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/Accordion/astro/index.d.ts +10 -10
  3. package/dist/components/Accordion/getProps.d.ts +40 -19
  4. package/dist/components/Accordion/react/AccIcon.d.ts +1 -6
  5. package/dist/components/Accordion/react/Accordion.d.ts +23 -7
  6. package/dist/components/Accordion/react/index.d.ts +6 -4
  7. package/dist/components/Accordion/setAccordion.d.ts +4 -1
  8. package/dist/components/Accordion/setAccordion.js +39 -42
  9. package/dist/components/Callout/getProps.d.ts +1 -1
  10. package/dist/components/Details/astro/index.d.ts +13 -0
  11. package/dist/components/Details/getProps.d.ts +40 -0
  12. package/dist/components/Details/react/Details.d.ts +37 -0
  13. package/dist/components/Details/react/index.d.ts +9 -0
  14. package/dist/components/Modal/getProps.d.ts +2 -2
  15. package/dist/components/Modal/setModal.d.ts +3 -0
  16. package/dist/components/Modal/setModal.js +25 -30
  17. package/dist/components/Tabs/getProps.d.ts +1 -1
  18. package/dist/components/astro.d.ts +1 -0
  19. package/dist/components/react.d.ts +1 -0
  20. package/dist/helper/animation.d.ts +18 -0
  21. package/dist/helper/animation.js +12 -0
  22. package/dist/helper/uuid.d.ts +1 -0
  23. package/dist/scripts/tabs.js +1 -1
  24. package/dist/style.css +1 -1
  25. package/package.json +68 -68
  26. package/src/components/Accordion/_style.css +61 -36
  27. package/src/components/Accordion/astro/Button.astro +13 -0
  28. package/src/components/Accordion/astro/Heading.astro +10 -0
  29. package/src/components/Accordion/astro/Icon.astro +15 -0
  30. package/src/components/Accordion/astro/Item.astro +31 -0
  31. package/src/components/Accordion/astro/Panel.astro +14 -0
  32. package/src/components/Accordion/astro/Root.astro +17 -0
  33. package/src/components/Accordion/astro/index.js +10 -7
  34. package/src/components/Accordion/getProps.js +61 -16
  35. package/src/components/Accordion/react/AccIcon.jsx +5 -4
  36. package/src/components/Accordion/react/Accordion.jsx +56 -28
  37. package/src/components/Accordion/react/index.js +6 -3
  38. package/src/components/Accordion/setAccordion.js +114 -88
  39. package/src/components/Callout/getProps.ts +1 -1
  40. package/src/components/Details/_style.css +48 -0
  41. package/src/components/Details/astro/Content.astro +17 -0
  42. package/src/components/Details/astro/Details.astro +18 -0
  43. package/src/components/Details/astro/Icon.astro +14 -0
  44. package/src/components/{Accordion/astro/AccLabel.astro → Details/astro/Summary.astro} +1 -2
  45. package/src/components/Details/astro/Title.astro +10 -0
  46. package/src/components/Details/astro/index.js +10 -0
  47. package/src/components/Details/getProps.js +23 -0
  48. package/src/components/Details/react/Details.jsx +66 -0
  49. package/src/components/Details/react/index.js +6 -0
  50. package/src/components/Modal/_style.css +7 -7
  51. package/src/components/Modal/getProps.js +3 -3
  52. package/src/components/Modal/script.js +1 -0
  53. package/src/components/Modal/setModal.ts +65 -69
  54. package/src/components/Tabs/_style.css +4 -4
  55. package/src/components/Tabs/astro/Tab.astro +1 -1
  56. package/src/components/Tabs/astro/TabList.astro +1 -1
  57. package/src/components/Tabs/astro/TabPanel.astro +1 -1
  58. package/src/components/Tabs/astro/Tabs.astro +4 -3
  59. package/src/components/Tabs/getProps.js +1 -1
  60. package/src/components/Tabs/react/Tab.jsx +1 -1
  61. package/src/components/Tabs/react/TabList.jsx +1 -1
  62. package/src/components/Tabs/react/TabPanel.jsx +1 -1
  63. package/src/components/Tabs/script.js +1 -1
  64. package/src/components/astro.ts +1 -0
  65. package/src/components/react.ts +1 -0
  66. package/src/helper/animation.ts +36 -0
  67. package/src/{components/Tabs/astro/helper.js → helper/uuid.js} +1 -1
  68. package/dist/components/Tabs/astro/helper.d.ts +0 -1
  69. package/src/components/Accordion/astro/AccBody.astro +0 -13
  70. package/src/components/Accordion/astro/AccHeader.astro +0 -13
  71. package/src/components/Accordion/astro/AccHeaderLabel.astro +0 -12
  72. package/src/components/Accordion/astro/AccIcon.astro +0 -17
  73. package/src/components/Accordion/astro/Accordion.astro +0 -22
package/package.json CHANGED
@@ -1,69 +1,69 @@
1
1
  {
2
- "name": "@lism-css/ui",
3
- "version": "0.2.2",
4
- "description": "UI components by lism-css.",
5
- "author": {
6
- "name": "ddryo",
7
- "url": "https://github.com/ddryo"
8
- },
9
- "license": "MIT",
10
- "keywords": [
11
- "css-framework",
12
- "astro-component",
13
- "react-component"
14
- ],
15
- "scripts": {
16
- "dev": "vite",
17
- "build": "vite build && pnpm build:css",
18
- "build:css": "node build-css.js"
19
- },
20
- "files": [
21
- "dist",
22
- "src"
23
- ],
24
- "type": "module",
25
- "main": "./dist/index.js",
26
- "exports": {
27
- "./react": {
28
- "import": "./src/components/react.js",
29
- "types": "./dist/components/index.d.ts"
30
- },
31
- "./astro": {
32
- "import": "./src/components/astro.js",
33
- "types": "./dist/components/index.d.ts"
34
- },
35
- "./scripts/*": "./dist/scripts/*.js",
36
- "./style.css": "./dist/style.css"
37
- },
38
- "homepage": "https://www.lism.style",
39
- "repository": {
40
- "type": "git",
41
- "url": "https://github.com/lism-css/lism-css/tree/main/packages/lism-css"
42
- },
43
- "bugs": {
44
- "url": "https://github.com/lism-css/lism-css/issues"
45
- },
46
- "dependencies": {
47
- "lism-css": "workspace:*"
48
- },
49
- "devDependencies": {
50
- "@babel/cli": "^7.27.2",
51
- "@babel/core": "^7.27.3",
52
- "@babel/preset-env": "^7.27.2",
53
- "@babel/preset-react": "^7.27.1",
54
- "@rollup/plugin-babel": "^6.0.4",
55
- "@vitejs/plugin-react-swc": "^3.10.0",
56
- "glob": "^11.0.2",
57
- "rollup": "^4.41.1",
58
- "typescript": "~5.8.3",
59
- "unplugin-dts": "1.0.0-beta.6",
60
- "vite": "^6.3.5"
61
- },
62
- "peerDependencies": {
63
- "@types/react": "*",
64
- "@types/react-dom": "*",
65
- "react": "^18 || ^19",
66
- "react-dom": "^18 || ^19"
67
- },
68
- "sideEffects": false
69
- }
2
+ "name": "@lism-css/ui",
3
+ "version": "0.8.0",
4
+ "description": "UI components by lism-css.",
5
+ "author": {
6
+ "name": "ddryo",
7
+ "url": "https://github.com/ddryo"
8
+ },
9
+ "license": "MIT",
10
+ "keywords": [
11
+ "css-framework",
12
+ "astro-component",
13
+ "react-component"
14
+ ],
15
+ "files": [
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "type": "module",
20
+ "main": "./dist/index.js",
21
+ "exports": {
22
+ "./react": {
23
+ "import": "./src/components/react.js",
24
+ "types": "./dist/components/index.d.ts"
25
+ },
26
+ "./astro": {
27
+ "import": "./src/components/astro.js",
28
+ "types": "./dist/components/index.d.ts"
29
+ },
30
+ "./scripts/*": "./dist/scripts/*.js",
31
+ "./style.css": "./dist/style.css"
32
+ },
33
+ "homepage": "https://www.lism.style",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/lism-css/lism-css/tree/main/packages/lism-css"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/lism-css/lism-css/issues"
40
+ },
41
+ "dependencies": {
42
+ "lism-css": "0.8.4"
43
+ },
44
+ "devDependencies": {
45
+ "@babel/cli": "^7.27.2",
46
+ "@babel/core": "^7.27.3",
47
+ "@babel/preset-env": "^7.27.2",
48
+ "@babel/preset-react": "^7.27.1",
49
+ "@rollup/plugin-babel": "^6.0.4",
50
+ "@vitejs/plugin-react-swc": "^3.10.0",
51
+ "glob": "^11.0.2",
52
+ "rollup": "^4.41.1",
53
+ "typescript": "~5.8.3",
54
+ "unplugin-dts": "1.0.0-beta.6",
55
+ "vite": "^6.3.5"
56
+ },
57
+ "peerDependencies": {
58
+ "@types/react": "*",
59
+ "@types/react-dom": "*",
60
+ "react": "^18 || ^19",
61
+ "react-dom": "^18 || ^19"
62
+ },
63
+ "sideEffects": false,
64
+ "scripts": {
65
+ "dev": "vite",
66
+ "build": "vite build && pnpm build:css",
67
+ "build:css": "node build-css.js"
68
+ }
69
+ }
@@ -1,54 +1,79 @@
1
1
  @layer lism.modules {
2
- .d--accordion {
2
+ .c--accordion {
3
3
  --duration: var(--acc-duration, 0.25s);
4
4
  }
5
- .d--accordion[data-opened] {
6
- --_notOpen: ;
5
+ .c--accordion_item {
6
+ --_panel-h: 0px;
7
+ --_icon-transform: rotate(0deg);
7
8
  }
8
- .d--accordion:not([data-opened]) {
9
- --_isOpen: ;
9
+
10
+ /* 開いている時 */
11
+ .c--accordion_item[data-opened] {
12
+ --_icon-transform: rotate(90deg);
13
+ --_panel-h: auto; /* Note: アニメーション時、jsでセットされる */
10
14
  }
11
15
 
12
- .d--accordion_header {
13
- display: grid;
14
- grid: auto / 1fr auto;
15
- gap: 0.5em;
16
- align-items: center;
17
- --focus-offset: -1px; /* overflow:hidden; で見えなくなってしまいがちなので内側に寄せておく */
18
-
19
- /* Safariで表示されるデフォルトの三角形アイコンを消す */
20
- &::-webkit-details-marker {
21
- display: none;
22
- }
16
+ /* .c--accordion_button {} */
17
+ .c--accordion_panel {
18
+ height: var(--_panel-h);
19
+ transition: height var(--duration);
23
20
  }
24
21
 
25
- .d--accordion_body {
26
- display: grid;
27
- grid: 1fr / auto;
28
- transition-property: margin-block, padding-block, opacity, grid-template;
29
- transition-duration: var(--duration);
22
+ /* コンテンツの paddingは __panel ではなくこっちにつける */
23
+ /* .c--accordion_content {} */
24
+
25
+ /* パネルが完全に閉じている時にabsoluteで飛ばしておくと、Chromeでも検索時に正常にハイライトされるようになる(なぜかは不明) */
26
+ [hidden] > .c--accordion_content {
27
+ position: absolute;
30
28
  }
31
29
 
32
- /* 正常な animation には必須 */
33
- .d--accordion_inner {
34
- overflow: hidden;
30
+ /* アイコンの描画 */
31
+ .c--accordion_icon {
32
+ display: grid;
33
+ width: 1em;
34
+ height: 1em;
35
+
36
+ &::before,
37
+ &::after {
38
+ content: '';
39
+ display: block;
40
+ grid-area: 1 / 1;
41
+ background-color: currentColor;
42
+ }
43
+ &::before {
44
+ width: 0.1em;
45
+ height: 100%;
46
+ transition: transform var(--duration);
47
+ transform: var(--_icon-transform);
48
+ }
49
+ &::after {
50
+ height: 0.1em;
51
+ width: 100%;
52
+ }
35
53
  }
36
54
 
37
- /* 閉じている時 */
38
- .d--accordion:not([data-opened]) > .d--accordion_body {
39
- grid: 0fr / auto;
40
- padding-block: 0 !important;
41
- margin-block: 0 !important;
55
+ /* フォーカス時のアウトラインを少し内側に寄せる( overflow:hidden によって途切れてしまうので) */
56
+ .c--accordion_button:focus-visible {
57
+ outline: solid 2px currentColor;
58
+ outline-color: revert;
59
+ outline-offset: -3px; /* offset 調整だけだとブラウザ間の差が大きい */
42
60
  }
43
61
 
44
- /* アコーディオンブロックのネスト時、別のアイコンタイプにすると表示が崩れるがそこまでは考慮しない。 */
45
- .d--accordion_icon {
46
- display: grid;
62
+ /* --- 「視差効果を減らす」設定を考慮 --- */
63
+ @media (prefers-reduced-motion: reduce) {
64
+ .c--accordion_item {
65
+ --duration: 0s;
66
+ }
47
67
  }
48
68
 
49
- /* .d--accordion_icon 自体にborderつけたりすると回転が見えてしまうので、中にある .a--icon を回転させる。 */
50
- .d--accordion_icon > .a--icon {
51
- transition: transform var(--duration);
52
- transform: var(--_isOpen, scaleY(-1));
69
+ /* --- JSオフ環境の考慮 --- */
70
+ @media (scripting: none) {
71
+ .c--accordion_panel {
72
+ height: auto !important;
73
+ content-visibility: visible !important;
74
+ }
75
+ .c--accordion_content {
76
+ position: static !important;
77
+ }
53
78
  }
54
79
  }
@@ -0,0 +1,13 @@
1
+ ---
2
+ import { Lism } from 'lism-css/astro';
3
+ import Icon from './Icon.astro';
4
+ import { defaultProps } from '../getProps';
5
+
6
+ // interface Props extends LismProps {}
7
+ const { isOpen = false, accID = '__LISM_ACC_ID__', ...props } = Astro.props || {};
8
+ ---
9
+
10
+ <Lism {...defaultProps.button} {...props} aria-controls={accID} aria-expanded={isOpen ? 'true' : 'false'}>
11
+ <slot />
12
+ <Icon />
13
+ </Lism>
@@ -0,0 +1,10 @@
1
+ ---
2
+ import { Lism } from 'lism-css/astro';
3
+ import { getHeadingProps } from '../getProps';
4
+
5
+ // interface Props extends LismProps {}
6
+ ---
7
+
8
+ <Lism {...getHeadingProps(Astro.props || {})}>
9
+ <slot />
10
+ </Lism>
@@ -0,0 +1,15 @@
1
+ ---
2
+ import { Lism } from 'lism-css/astro';
3
+ import { defaultProps } from '../getProps';
4
+
5
+ // Propsの定義
6
+ // interface Props extends LismProps {
7
+ // icon?: string;
8
+ // size?: string;
9
+ // iconProps?: Object;
10
+ // }
11
+
12
+ const props = Astro.props || {};
13
+ ---
14
+
15
+ <Lism {...defaultProps.icon} {...props} />
@@ -0,0 +1,31 @@
1
+ ---
2
+ // scriptを使うので ref の関係で <Lism> ではなく getLismProps() を使う
3
+ import getLismProps from 'lism-css/lib/getLismProps';
4
+ import { getItemProps } from '../getProps';
5
+ import uuid from '../../../helper/uuid.js';
6
+
7
+ import '../_style.css';
8
+
9
+ const { accID: _accID, ...restProps } = Astro.props || {};
10
+
11
+ // aria-controls / id 紐付け用のIDを生成(カスタム指定があればそれを使用、なければ自動生成)
12
+ const accID = _accID || uuid();
13
+
14
+ const lismProps = getLismProps(getItemProps(restProps));
15
+
16
+ // 子要素のHTMLを取得し、プレースホルダーの有無で出力方法を切り替え
17
+ // - プレースホルダーあり → 置換して set:html で出力
18
+ // - プレースホルダーなし → 通常の slot 出力(Button/Panel に直接 accID を指定しているケース)
19
+ const rendered = await Astro.slots.render('default');
20
+ const slotHtml = rendered.includes('__LISM_ACC_ID__') ? rendered.replaceAll('__LISM_ACC_ID__', accID) : null;
21
+ ---
22
+
23
+ {
24
+ slotHtml !== null ? (
25
+ <div {...lismProps} set:html={slotHtml} />
26
+ ) : (
27
+ <div {...lismProps}>
28
+ <slot />
29
+ </div>
30
+ )
31
+ }
@@ -0,0 +1,14 @@
1
+ ---
2
+ // import type { LismProps } from 'lism-css/types';
3
+ import { Lism } from 'lism-css/astro';
4
+ import { getPanelProps } from '../getProps';
5
+
6
+ // interface Props extends LismProps {}
7
+ const { panelProps, contentProps } = getPanelProps(Astro.props || {});
8
+ ---
9
+
10
+ <Lism {...panelProps}>
11
+ <Lism {...contentProps}>
12
+ <slot />
13
+ </Lism>
14
+ </Lism>
@@ -0,0 +1,17 @@
1
+ ---
2
+ import { Stack } from 'lism-css/astro';
3
+ import { getRootProps } from '../getProps';
4
+
5
+ import '../_style.css';
6
+
7
+ const rootProps = getRootProps(Astro.props || {});
8
+ ---
9
+
10
+ <Stack {...rootProps}>
11
+ <slot />
12
+ </Stack>
13
+
14
+ <script>
15
+ import setAccordion from '../setAccordion';
16
+ setAccordion();
17
+ </script>
@@ -1,8 +1,11 @@
1
- import Root from './Accordion.astro';
2
- import Header from './AccHeader.astro';
3
- import Label from './AccLabel.astro';
4
- import Icon from './AccIcon.astro';
5
- import Body from './AccBody.astro';
6
- import HeaderLabel from './AccHeaderLabel.astro';
1
+ import Root from './Root.astro';
2
+ import Item from './Item.astro';
3
+ import Heading from './Heading.astro';
4
+ import Button from './Button.astro';
5
+ import Icon from './Icon.astro';
6
+ import Panel from './Panel.astro';
7
7
 
8
- export default { Root, Header, HeaderLabel, Body, Icon, Label };
8
+ // Header: Heading, Button, Iconのセット
9
+ // Body: Panel の別名(ドキュメント向け)
10
+
11
+ export default { Root, Item, Heading, Panel, Icon, Button };
@@ -1,32 +1,77 @@
1
1
  import atts from 'lism-css/lib/helper/atts';
2
2
 
3
+ export function getRootProps({ lismClass, allowMultiple, ...props }) {
4
+ props.lismClass = atts(lismClass, 'c--accordion');
5
+ if (allowMultiple) props['data-allow-multiple'] = 'true';
6
+ return props;
7
+ }
8
+
3
9
  // duration: [s]
4
- export function getAccProps({ lismClass, ...props }) {
5
- props.lismClass = atts(lismClass, 'd--accordion');
10
+ export function getItemProps({ lismClass, ...props }) {
11
+ props.lismClass = atts(lismClass, 'c--accordion_item');
6
12
  return props;
7
13
  }
8
14
 
9
- export function getAccIconProps({ isTrigger, ...props }) {
15
+ export function getHeadingProps(props) {
10
16
  const defaultProps = {
11
- lismClass: 'd--accordion_icon',
12
- tag: 'span',
17
+ lismClass: 'c--accordion_heading',
18
+ tag: 'div',
19
+ setPlain: 1,
13
20
  };
14
- // isTrigger なら、buttun にする
15
- if (isTrigger) {
16
- defaultProps.tag = 'button';
17
- props['data-role'] = 'trigger';
21
+
22
+ const returnProps = { ...defaultProps, ...props };
23
+
24
+ // div の時は role 付与
25
+ if (returnProps.tag === 'div') {
26
+ returnProps.role = 'heading';
18
27
  }
28
+ return returnProps;
29
+ }
30
+
31
+ // id: Context から取得できればそれを優先(React用)
32
+ export function getPanelProps({ lismClass, _contextID, accID = '__LISM_ACC_ID__', isOpen = false, ...props }) {
33
+ // panel側は必要最低限のプロパティのみ。
34
+ const panelProps = {
35
+ lismClass: atts(lismClass, 'c--accordion_panel'),
36
+ id: _contextID || accID,
37
+ hidden: isOpen ? undefined : 'until-found',
38
+ pos: 'relative',
39
+ ov: 'hidden',
40
+ };
19
41
 
20
- return { ...defaultProps, ...props };
42
+ // 余白などその他の指定は全て _content 側へ渡す
43
+ const contentProps = { lismClass: 'c--accordion_content', layout: 'flow', ...props };
44
+
45
+ // content側へ移すprops
46
+ // ['p', 'px', 'py', 'pl', 'pr', 'pt', 'pb', 'px-s', 'px-e', 'py-s', 'py-e'].forEach((prop) => {
47
+ // if (props[prop]) {
48
+ // contentProps[prop] = props[prop];
49
+ // delete props[prop];
50
+ // }
51
+ // });
52
+
53
+ // 2つ返す
54
+ return { panelProps, contentProps };
21
55
  }
22
56
 
23
57
  export const defaultProps = {
24
- header: { lismClass: 'd--accordion_header' },
25
- label: { lismClass: 'd--accordion_label', tag: 'span' },
26
- body: {
27
- lismClass: 'd--accordion_body',
58
+ // header: { lismClass: 'c--accordion_header' },
59
+ button: {
60
+ lismClass: 'c--accordion_button',
61
+ tag: 'button',
62
+ layout: 'flex',
63
+ setPlain: 1,
64
+ g: '10',
65
+ w: '100%',
66
+ ai: 'center',
67
+ jc: 'between',
28
68
  },
29
- inner: {
30
- lismClass: 'd--accordion_inner',
69
+ icon: {
70
+ lismClass: 'c--accordion_icon a--icon',
71
+ tag: 'span',
72
+ // d: 'grid',
73
+ pi: 'center',
74
+ fxsh: '0',
75
+ 'aria-hidden': 'true',
31
76
  },
32
77
  };
@@ -1,6 +1,7 @@
1
- import { Lism, Icon } from 'lism-css/react';
2
- import { getAccIconProps } from '../getProps';
1
+ import { Lism } from 'lism-css/react';
2
+ import { defaultProps } from '../getProps';
3
3
 
4
- export default function AccIcon({ icon = 'caret-down', viewBox, children = null, ...props }) {
5
- return <Lism {...getAccIconProps(props)}>{children || <Icon viewBox={viewBox} icon={icon} />}</Lism>;
4
+ // CSS疑似要素(::before / ::after)でアイコンを描画するコンポーネント
5
+ export default function AccIcon(props) {
6
+ return <Lism {...defaultProps.icon} {...props} />;
6
7
  }
@@ -1,56 +1,84 @@
1
1
  import React from 'react';
2
2
  import getLismProps from 'lism-css/lib/getLismProps';
3
- import { Lism } from 'lism-css/react';
4
- import { getAccProps, defaultProps } from '../getProps';
3
+ import { Lism, Stack } from 'lism-css/react';
4
+ import { getRootProps, getItemProps, getHeadingProps, getPanelProps, defaultProps } from '../getProps';
5
5
  import { setEvent } from '../setAccordion';
6
6
  import AccIcon from './AccIcon';
7
7
 
8
8
  import '../_style.css';
9
9
 
10
- export function Accordion({ children, ...props }) {
10
+ // Context: 純粋なReact環境で AccordionItem Button / Panel へ accID を共有
11
+ // Astro 環境では Context が使えないため null がフォールバック
12
+ const AccordionContext = React.createContext(null);
13
+
14
+ /**
15
+ * 複数の AccordionItem をラップするルート要素
16
+ */
17
+ export function AccordionRoot({ children, ...props }) {
18
+ const rootProps = getRootProps(props);
19
+ return <Stack {...rootProps}>{children}</Stack>;
20
+ }
21
+
22
+ /**
23
+ * 個別のアコーディオンアイテム(<div> ベース、setEvent で開閉イベントを登録)
24
+ */
25
+ export function AccordionItem({ children, ...props }) {
11
26
  const ref = React.useRef(null);
12
27
 
28
+ // コンポーネント単位でユニークIDを生成
29
+ const accID = React.useId();
30
+
31
+ // マウント時に開閉イベントを登録(アンマウント時にクリーンアップ)
13
32
  React.useEffect(() => {
14
33
  if (!ref.current) return;
15
34
  return setEvent(ref.current);
16
35
  }, []);
17
36
 
18
- const lismProps = getLismProps(getAccProps(props));
37
+ const lismProps = getLismProps(getItemProps(props));
19
38
 
20
39
  return (
21
- <details ref={ref} {...lismProps}>
22
- {children}
23
- </details>
40
+ <AccordionContext.Provider value={{ accID }}>
41
+ <div ref={ref} {...lismProps}>
42
+ {children}
43
+ </div>
44
+ </AccordionContext.Provider>
24
45
  );
25
46
  }
26
- export function Header({ children, ...props }) {
27
- return (
28
- <Lism tag='summary' {...defaultProps.header} {...props}>
29
- {children}
30
- </Lism>
31
- );
47
+
48
+ /**
49
+ * 見出しエリアのラッパー(デフォルトは <div role="heading">)
50
+ * tag に h2〜h6 を指定すると role は付与されない
51
+ */
52
+ export function Heading({ children, ...props }) {
53
+ return <Lism {...getHeadingProps(props)}>{children}</Lism>;
32
54
  }
33
- export function Label({ children, ...props }) {
55
+
56
+ /**
57
+ * 開閉トリガーボタン
58
+ * accID: Context から取得できればそれを優先、なければ props / プレースホルダー
59
+ */
60
+ export function Button({ children, accID: _accID = '__LISM_ACC_ID__', ...props }) {
61
+ const ctx = React.useContext(AccordionContext);
62
+ const accID = ctx?.accID || _accID;
63
+
34
64
  return (
35
- <Lism {...defaultProps.label} {...props}>
65
+ <Lism {...defaultProps.button} {...props} aria-controls={accID} aria-expanded='false'>
36
66
  {children}
67
+ <AccIcon />
37
68
  </Lism>
38
69
  );
39
70
  }
40
- export function Body({ children, flow, innerProps, ...props }) {
71
+
72
+ /**
73
+ * パネル
74
+ */
75
+ export function Panel({ children, ...props }) {
76
+ const ctx = React.useContext(AccordionContext);
77
+ const { panelProps, contentProps } = getPanelProps({ _contextID: ctx?.accID, ...props });
78
+
41
79
  return (
42
- <Lism {...defaultProps.body} {...props}>
43
- <Lism layout='flow' flow={flow} {...defaultProps.inner} {...innerProps}>
44
- {children}
45
- </Lism>
80
+ <Lism {...panelProps}>
81
+ <Lism {...contentProps}>{children}</Lism>
46
82
  </Lism>
47
83
  );
48
84
  }
49
- export function HeaderLabel({ children, ...props }) {
50
- return (
51
- <Header {...props}>
52
- <Label>{children}</Label>
53
- <AccIcon />
54
- </Header>
55
- );
56
- }
@@ -1,4 +1,7 @@
1
- import { Accordion as Root, Header, Label, Body, HeaderLabel } from './Accordion';
2
- import { default as Icon } from './AccIcon';
1
+ import { AccordionRoot as Root, AccordionItem as Item, Heading, Button, Panel } from './Accordion';
2
+ import Icon from './AccIcon';
3
3
 
4
- export default { Root, Header, Label, Icon, Body, HeaderLabel };
4
+ // Header Heading のエイリアス
5
+ const Header = Heading;
6
+
7
+ export default { Root, Item, Header, Heading, Panel, Icon, Button };