@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.
- package/LICENSE +21 -0
- package/dist/components/Accordion/astro/index.d.ts +10 -10
- package/dist/components/Accordion/getProps.d.ts +40 -19
- package/dist/components/Accordion/react/AccIcon.d.ts +1 -6
- package/dist/components/Accordion/react/Accordion.d.ts +23 -7
- package/dist/components/Accordion/react/index.d.ts +6 -4
- package/dist/components/Accordion/setAccordion.d.ts +4 -1
- package/dist/components/Accordion/setAccordion.js +39 -42
- package/dist/components/Callout/getProps.d.ts +1 -1
- package/dist/components/Details/astro/index.d.ts +13 -0
- package/dist/components/Details/getProps.d.ts +40 -0
- package/dist/components/Details/react/Details.d.ts +37 -0
- package/dist/components/Details/react/index.d.ts +9 -0
- package/dist/components/Modal/getProps.d.ts +2 -2
- package/dist/components/Modal/setModal.d.ts +3 -0
- package/dist/components/Modal/setModal.js +25 -30
- package/dist/components/Tabs/getProps.d.ts +1 -1
- package/dist/components/astro.d.ts +1 -0
- package/dist/components/react.d.ts +1 -0
- package/dist/helper/animation.d.ts +18 -0
- package/dist/helper/animation.js +12 -0
- package/dist/helper/uuid.d.ts +1 -0
- package/dist/scripts/tabs.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +68 -68
- package/src/components/Accordion/_style.css +61 -36
- package/src/components/Accordion/astro/Button.astro +13 -0
- package/src/components/Accordion/astro/Heading.astro +10 -0
- package/src/components/Accordion/astro/Icon.astro +15 -0
- package/src/components/Accordion/astro/Item.astro +31 -0
- package/src/components/Accordion/astro/Panel.astro +14 -0
- package/src/components/Accordion/astro/Root.astro +17 -0
- package/src/components/Accordion/astro/index.js +10 -7
- package/src/components/Accordion/getProps.js +61 -16
- package/src/components/Accordion/react/AccIcon.jsx +5 -4
- package/src/components/Accordion/react/Accordion.jsx +56 -28
- package/src/components/Accordion/react/index.js +6 -3
- package/src/components/Accordion/setAccordion.js +114 -88
- package/src/components/Callout/getProps.ts +1 -1
- package/src/components/Details/_style.css +48 -0
- package/src/components/Details/astro/Content.astro +17 -0
- package/src/components/Details/astro/Details.astro +18 -0
- package/src/components/Details/astro/Icon.astro +14 -0
- package/src/components/{Accordion/astro/AccLabel.astro → Details/astro/Summary.astro} +1 -2
- package/src/components/Details/astro/Title.astro +10 -0
- package/src/components/Details/astro/index.js +10 -0
- package/src/components/Details/getProps.js +23 -0
- package/src/components/Details/react/Details.jsx +66 -0
- package/src/components/Details/react/index.js +6 -0
- package/src/components/Modal/_style.css +7 -7
- package/src/components/Modal/getProps.js +3 -3
- package/src/components/Modal/script.js +1 -0
- package/src/components/Modal/setModal.ts +65 -69
- package/src/components/Tabs/_style.css +4 -4
- package/src/components/Tabs/astro/Tab.astro +1 -1
- package/src/components/Tabs/astro/TabList.astro +1 -1
- package/src/components/Tabs/astro/TabPanel.astro +1 -1
- package/src/components/Tabs/astro/Tabs.astro +4 -3
- package/src/components/Tabs/getProps.js +1 -1
- package/src/components/Tabs/react/Tab.jsx +1 -1
- package/src/components/Tabs/react/TabList.jsx +1 -1
- package/src/components/Tabs/react/TabPanel.jsx +1 -1
- package/src/components/Tabs/script.js +1 -1
- package/src/components/astro.ts +1 -0
- package/src/components/react.ts +1 -0
- package/src/helper/animation.ts +36 -0
- package/src/{components/Tabs/astro/helper.js → helper/uuid.js} +1 -1
- package/dist/components/Tabs/astro/helper.d.ts +0 -1
- package/src/components/Accordion/astro/AccBody.astro +0 -13
- package/src/components/Accordion/astro/AccHeader.astro +0 -13
- package/src/components/Accordion/astro/AccHeaderLabel.astro +0 -12
- package/src/components/Accordion/astro/AccIcon.astro +0 -17
- package/src/components/Accordion/astro/Accordion.astro +0 -22
package/package.json
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
.
|
|
2
|
+
.c--accordion {
|
|
3
3
|
--duration: var(--acc-duration, 0.25s);
|
|
4
4
|
}
|
|
5
|
-
.
|
|
6
|
-
--
|
|
5
|
+
.c--accordion_item {
|
|
6
|
+
--_panel-h: 0px;
|
|
7
|
+
--_icon-transform: rotate(0deg);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
/* 開いている時 */
|
|
11
|
+
.c--accordion_item[data-opened] {
|
|
12
|
+
--_icon-transform: rotate(90deg);
|
|
13
|
+
--_panel-h: auto; /* Note: アニメーション時、jsでセットされる */
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
/* コンテンツの paddingは __panel ではなくこっちにつける */
|
|
23
|
+
/* .c--accordion_content {} */
|
|
24
|
+
|
|
25
|
+
/* パネルが完全に閉じている時にabsoluteで飛ばしておくと、Chromeでも検索時に正常にハイライトされるようになる(なぜかは不明) */
|
|
26
|
+
[hidden] > .c--accordion_content {
|
|
27
|
+
position: absolute;
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
/*
|
|
33
|
-
.
|
|
34
|
-
|
|
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
|
-
.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
46
|
-
|
|
62
|
+
/* --- 「視差効果を減らす」設定を考慮 --- */
|
|
63
|
+
@media (prefers-reduced-motion: reduce) {
|
|
64
|
+
.c--accordion_item {
|
|
65
|
+
--duration: 0s;
|
|
66
|
+
}
|
|
47
67
|
}
|
|
48
68
|
|
|
49
|
-
/*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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,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 './
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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
|
-
|
|
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
|
|
5
|
-
props.lismClass = atts(lismClass, '
|
|
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
|
|
15
|
+
export function getHeadingProps(props) {
|
|
10
16
|
const defaultProps = {
|
|
11
|
-
lismClass: '
|
|
12
|
-
tag: '
|
|
17
|
+
lismClass: 'c--accordion_heading',
|
|
18
|
+
tag: 'div',
|
|
19
|
+
setPlain: 1,
|
|
13
20
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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: '
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
lismClass: '
|
|
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
|
|
2
|
-
import {
|
|
1
|
+
import { Lism } from 'lism-css/react';
|
|
2
|
+
import { defaultProps } from '../getProps';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
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 {
|
|
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
|
-
|
|
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(
|
|
37
|
+
const lismProps = getLismProps(getItemProps(props));
|
|
19
38
|
|
|
20
39
|
return (
|
|
21
|
-
<
|
|
22
|
-
{
|
|
23
|
-
|
|
40
|
+
<AccordionContext.Provider value={{ accID }}>
|
|
41
|
+
<div ref={ref} {...lismProps}>
|
|
42
|
+
{children}
|
|
43
|
+
</div>
|
|
44
|
+
</AccordionContext.Provider>
|
|
24
45
|
);
|
|
25
46
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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.
|
|
65
|
+
<Lism {...defaultProps.button} {...props} aria-controls={accID} aria-expanded='false'>
|
|
36
66
|
{children}
|
|
67
|
+
<AccIcon />
|
|
37
68
|
</Lism>
|
|
38
69
|
);
|
|
39
70
|
}
|
|
40
|
-
|
|
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 {...
|
|
43
|
-
<Lism
|
|
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 {
|
|
2
|
-
import
|
|
1
|
+
import { AccordionRoot as Root, AccordionItem as Item, Heading, Button, Panel } from './Accordion';
|
|
2
|
+
import Icon from './AccIcon';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Header は Heading のエイリアス
|
|
5
|
+
const Header = Heading;
|
|
6
|
+
|
|
7
|
+
export default { Root, Item, Header, Heading, Panel, Icon, Button };
|