@growth-angels/ds-core 1.2.0 → 1.3.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/organisms/Tabs/Tabs.d.ts +2 -0
- package/dist/organisms/Tabs/Tabs.js +19 -0
- package/dist/organisms/Tabs/Tabs.stories.d.ts +6 -0
- package/dist/organisms/Tabs/Tabs.stories.js +23 -0
- package/dist/organisms/Tabs/Tabs.types.d.ts +9 -0
- package/dist/organisms/Tabs/Tabs.types.js +1 -0
- package/dist/organisms/organisms.d.ts +2 -0
- package/dist/organisms/organisms.js +2 -0
- package/package.json +1 -1
- package/src/atoms/Button/Button.scss +5 -5
- package/src/organisms/Tabs/Tabs.scss +28 -0
- package/src/organisms/Tabs/Tabs.stories.tsx +26 -0
- package/src/organisms/Tabs/Tabs.tsx +53 -0
- package/src/organisms/Tabs/Tabs.types.ts +10 -0
- package/src/organisms/organisms.scss +1 -0
- package/src/organisms/organisms.ts +3 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useReactAdapter } from "../../hooks/useReactAdaptater";
|
|
3
|
+
export const Tabs = ({ tabs, children, extraClassNames, edit }) => {
|
|
4
|
+
const { useEffect, useState, useRef, Children, Fragment } = useReactAdapter();
|
|
5
|
+
console.log(edit);
|
|
6
|
+
const [activeTab, setActiveTab] = useState(tabs[0]?.id || "");
|
|
7
|
+
const tabsRef = useRef([]);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const activeIndex = tabs.findIndex((tab) => tab.id === activeTab);
|
|
10
|
+
tabsRef.current[activeIndex]?.focus();
|
|
11
|
+
}, [activeTab, tabs]);
|
|
12
|
+
const classes = ["ga-ds-tabs"];
|
|
13
|
+
if (extraClassNames) {
|
|
14
|
+
classes.push(...extraClassNames);
|
|
15
|
+
}
|
|
16
|
+
return (_jsxs("div", { className: classes.join(" "), children: [_jsx("div", { className: "ga-ds-tabs__list", role: "tablist", children: tabs.map((tab, index) => (_jsx("button", { ref: (el) => (tabsRef.current[index] = el), role: "tab", "aria-selected": activeTab === tab.id, "aria-controls": `ga-ds-tabpanel-${tab.id}`, id: `ga-ds-tab-${tab.id}`, tabIndex: activeTab === tab.id ? 0 : -1, className: `ga-ds-tabs__tab ${activeTab === tab.id ? "ga-ds-tabs__tab--active" : ""}`, onClick: () => setActiveTab(tab.id), children: tab.label }, tab.id))) }), _jsx("div", { className: "ga-ds-tabs__panels", children: !edit
|
|
17
|
+
? Children.toArray(children).map((child) => (_jsx("div", { className: ["ga-ds-tabs__panel", activeTab === child.props.id ? "ga-ds-tabs__panel--active" : ""].join(" "), children: _jsx("div", { role: "tabpanel", id: `ga-ds-tabpanel-${child.props.id}`, "aria-labelledby": `ga-ds-tab-${child.props.id}`, children: child }) }, child.props.id)))
|
|
18
|
+
: children })] }));
|
|
19
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Tabs } from "./Tabs";
|
|
3
|
+
const meta = {
|
|
4
|
+
title: "Organisms/Tabs",
|
|
5
|
+
component: Tabs,
|
|
6
|
+
tags: ["autodocs"],
|
|
7
|
+
};
|
|
8
|
+
export default meta;
|
|
9
|
+
const ids = Array.from({ length: 3 }, () => crypto.randomUUID());
|
|
10
|
+
export const Primary = {
|
|
11
|
+
args: {
|
|
12
|
+
tabs: [
|
|
13
|
+
{ id: ids[0], label: "Tab 1" },
|
|
14
|
+
{ id: ids[1], label: "Tab 2" },
|
|
15
|
+
{ id: ids[2], label: "Tab 3" },
|
|
16
|
+
],
|
|
17
|
+
children: [
|
|
18
|
+
_jsx("div", { id: ids[0], children: "Content for Tab 1" }),
|
|
19
|
+
_jsx("div", { id: ids[1], children: "Content for Tab 2" }),
|
|
20
|
+
_jsx("div", { id: ids[2], children: "Content for Tab 3" }),
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.ga-ds-button >
|
|
1
|
+
.ga-ds-button > .wp-block-button__link.wp-element-button,
|
|
2
2
|
button.ga-ds-button {
|
|
3
3
|
padding: var(--ga-button-padding);
|
|
4
4
|
border: none;
|
|
@@ -9,25 +9,25 @@ button.ga-ds-button {
|
|
|
9
9
|
cursor: pointer;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
.ga-ds-button--primary >
|
|
12
|
+
.ga-ds-button--primary > .wp-block-button__link.wp-element-button,
|
|
13
13
|
button.ga-ds-button--primary {
|
|
14
14
|
background-color: var(--ga-button-background-primary, #eee);
|
|
15
15
|
color: var(--ga-button-color-primary, #000);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
.ga-ds-button--secondary >
|
|
18
|
+
.ga-ds-button--secondary > .wp-block-button__link.wp-element-button,
|
|
19
19
|
button.ga-ds-button--secondary {
|
|
20
20
|
background-color: var(--ga-button-background-secondary, #424242);
|
|
21
21
|
color: var(--ga-button-color-secondary, #fff);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
.ga-ds-button--link >
|
|
24
|
+
.ga-ds-button--link > .wp-block-button__link.wp-element-button,
|
|
25
25
|
button.ga-ds-button--link {
|
|
26
26
|
color: var(--ga-button-color-link, purple);
|
|
27
27
|
padding: 0;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
.ga-ds-button--icon >
|
|
30
|
+
.ga-ds-button--icon > .wp-block-button__link.wp-element-button,
|
|
31
31
|
button.ga-ds-button--icon {
|
|
32
32
|
--ga-button-padding: 0.8rem 1.2rem;
|
|
33
33
|
justify-content: center;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
.ga-ds-tabs {
|
|
2
|
+
outline: 1px solid red;
|
|
3
|
+
$this: &;
|
|
4
|
+
&__list {
|
|
5
|
+
display: flex;
|
|
6
|
+
|
|
7
|
+
#{$this}__tab {
|
|
8
|
+
background: none;
|
|
9
|
+
border: none;
|
|
10
|
+
font-size: inherit;
|
|
11
|
+
padding: inherit;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&__panel {
|
|
16
|
+
height: 0;
|
|
17
|
+
visibility: hidden;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
clip-path: inset(100% 0 0 0);
|
|
20
|
+
|
|
21
|
+
&--active {
|
|
22
|
+
height: auto;
|
|
23
|
+
visibility: visible;
|
|
24
|
+
overflow: visible;
|
|
25
|
+
clip-path: none;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
2
|
+
import { Tabs } from "./Tabs"
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Tabs> = {
|
|
5
|
+
title: "Organisms/Tabs",
|
|
6
|
+
component: Tabs,
|
|
7
|
+
tags: ["autodocs"],
|
|
8
|
+
}
|
|
9
|
+
export default meta
|
|
10
|
+
type Story = StoryObj<typeof Tabs>
|
|
11
|
+
|
|
12
|
+
const ids = Array.from({ length: 3 }, () => crypto.randomUUID())
|
|
13
|
+
export const Primary: Story = {
|
|
14
|
+
args: {
|
|
15
|
+
tabs: [
|
|
16
|
+
{ id: ids[0], label: "Tab 1" },
|
|
17
|
+
{ id: ids[1], label: "Tab 2" },
|
|
18
|
+
{ id: ids[2], label: "Tab 3" },
|
|
19
|
+
],
|
|
20
|
+
children: [
|
|
21
|
+
<div id={ids[0]}>Content for Tab 1</div>,
|
|
22
|
+
<div id={ids[1]}>Content for Tab 2</div>,
|
|
23
|
+
<div id={ids[2]}>Content for Tab 3</div>,
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useReactAdapter } from "../../hooks/useReactAdaptater"
|
|
2
|
+
import { TabsProps } from "./Tabs.types"
|
|
3
|
+
export const Tabs = ({ tabs, children, extraClassNames, edit }: TabsProps) => {
|
|
4
|
+
const { useEffect, useState, useRef, Children, Fragment } = useReactAdapter()
|
|
5
|
+
console.log(edit)
|
|
6
|
+
const [activeTab, setActiveTab] = useState(tabs[0]?.id || "")
|
|
7
|
+
const tabsRef = useRef<Array<HTMLButtonElement | null>>([])
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const activeIndex = tabs.findIndex((tab) => tab.id === activeTab)
|
|
11
|
+
tabsRef.current[activeIndex]?.focus()
|
|
12
|
+
}, [activeTab, tabs])
|
|
13
|
+
|
|
14
|
+
const classes = ["ga-ds-tabs"]
|
|
15
|
+
if (extraClassNames) {
|
|
16
|
+
classes.push(...extraClassNames)
|
|
17
|
+
}
|
|
18
|
+
return (
|
|
19
|
+
<div className={classes.join(" ")}>
|
|
20
|
+
<div className="ga-ds-tabs__list" role="tablist">
|
|
21
|
+
{tabs.map((tab, index) => (
|
|
22
|
+
<button
|
|
23
|
+
key={tab.id}
|
|
24
|
+
ref={(el) => (tabsRef.current[index] = el)}
|
|
25
|
+
role="tab"
|
|
26
|
+
aria-selected={activeTab === tab.id}
|
|
27
|
+
aria-controls={`ga-ds-tabpanel-${tab.id}`}
|
|
28
|
+
id={`ga-ds-tab-${tab.id}`}
|
|
29
|
+
tabIndex={activeTab === tab.id ? 0 : -1}
|
|
30
|
+
className={`ga-ds-tabs__tab ${activeTab === tab.id ? "ga-ds-tabs__tab--active" : ""}`}
|
|
31
|
+
onClick={() => setActiveTab(tab.id)}
|
|
32
|
+
>
|
|
33
|
+
{tab.label}
|
|
34
|
+
</button>
|
|
35
|
+
))}
|
|
36
|
+
</div>
|
|
37
|
+
<div className="ga-ds-tabs__panels">
|
|
38
|
+
{!edit
|
|
39
|
+
? Children.toArray(children).map((child: any) => (
|
|
40
|
+
<div
|
|
41
|
+
key={child.props.id}
|
|
42
|
+
className={["ga-ds-tabs__panel", activeTab === child.props.id ? "ga-ds-tabs__panel--active" : ""].join(" ")}
|
|
43
|
+
>
|
|
44
|
+
<div role="tabpanel" id={`ga-ds-tabpanel-${child.props.id}`} aria-labelledby={`ga-ds-tab-${child.props.id}`}>
|
|
45
|
+
{child}
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
))
|
|
49
|
+
: children}
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
)
|
|
53
|
+
}
|