@nucleux/md3-tabs 0.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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nucleux
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @nucleux/md3-tabs
|
|
2
|
+
|
|
3
|
+
Material 3 primary tabs — Nucleux agentic UI for React.
|
|
4
|
+
|
|
5
|
+
Part of **[Nucleux](https://github.com/intelligaia-open-labs/nucleux)** — agentic UI components for React. Install a single component, or the full kit via [`@nucleux/react`](https://www.npmjs.com/package/@nucleux/react).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @nucleux/md3-tabs @nucleux/tokens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` / `react-dom` are peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Md3Tabs } from "@nucleux/md3-tabs";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires the theme once in your app: `import "@nucleux/tokens/styles.css";`
|
|
22
|
+
and the Tailwind preset from `@nucleux/tokens/preset`.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT © Nucleux
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var utils = require('@nucleux/utils');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
|
+
|
|
28
|
+
// src/index.tsx
|
|
29
|
+
var TabsContext = React__namespace.createContext(null);
|
|
30
|
+
var useTabs = (c) => {
|
|
31
|
+
const ctx = React__namespace.useContext(TabsContext);
|
|
32
|
+
if (!ctx) throw new Error(`${c} must be used within Md3Tabs`);
|
|
33
|
+
return ctx;
|
|
34
|
+
};
|
|
35
|
+
var Md3Tabs = React__namespace.forwardRef(
|
|
36
|
+
({ value, defaultValue, onValueChange, className, children, ...props }, ref) => {
|
|
37
|
+
const isControlled = value !== void 0;
|
|
38
|
+
const [internal, setInternal] = React__namespace.useState(defaultValue);
|
|
39
|
+
const current = isControlled ? value : internal;
|
|
40
|
+
const setValue = (v) => {
|
|
41
|
+
if (!isControlled) setInternal(v);
|
|
42
|
+
onValueChange?.(v);
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className, ...props, children: /* @__PURE__ */ jsxRuntime.jsx(TabsContext.Provider, { value: { value: current, setValue }, children }) });
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
Md3Tabs.displayName = "Md3Tabs";
|
|
48
|
+
var Md3TabsList = React__namespace.forwardRef(
|
|
49
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, role: "tablist", className: utils.cn("flex border-b border-md-surface-variant bg-md-surface", className), ...props })
|
|
50
|
+
);
|
|
51
|
+
Md3TabsList.displayName = "Md3TabsList";
|
|
52
|
+
var Md3Tab = React__namespace.forwardRef(
|
|
53
|
+
({ value, icon, className, children, ...props }, ref) => {
|
|
54
|
+
const { value: active, setValue } = useTabs("Md3Tab");
|
|
55
|
+
const selected = active === value;
|
|
56
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
57
|
+
"button",
|
|
58
|
+
{
|
|
59
|
+
ref,
|
|
60
|
+
type: "button",
|
|
61
|
+
role: "tab",
|
|
62
|
+
"aria-selected": selected,
|
|
63
|
+
onClick: () => setValue(value),
|
|
64
|
+
className: utils.cn(
|
|
65
|
+
"relative inline-flex h-12 flex-1 items-center justify-center gap-2 overflow-hidden px-4 text-sm font-medium transition-colors [&_svg]:size-5",
|
|
66
|
+
"before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:content-['']",
|
|
67
|
+
"hover:before:opacity-[0.08] focus-visible:before:opacity-[0.12]",
|
|
68
|
+
"outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-md-primary",
|
|
69
|
+
selected ? "text-md-primary" : "text-md-on-surface-variant",
|
|
70
|
+
className
|
|
71
|
+
),
|
|
72
|
+
...props,
|
|
73
|
+
children: [
|
|
74
|
+
icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "relative", children: icon }),
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "relative", children }),
|
|
76
|
+
selected && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, className: "absolute inset-x-0 bottom-0 mx-auto h-[3px] w-3/5 rounded-t-full bg-md-primary" })
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
Md3Tab.displayName = "Md3Tab";
|
|
83
|
+
var Md3TabPanel = React__namespace.forwardRef(
|
|
84
|
+
({ value, className, ...props }, ref) => {
|
|
85
|
+
const { value: active } = useTabs("Md3TabPanel");
|
|
86
|
+
if (active !== value) return null;
|
|
87
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, role: "tabpanel", className: utils.cn("p-4 text-md-on-surface", className), ...props });
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
Md3TabPanel.displayName = "Md3TabPanel";
|
|
91
|
+
|
|
92
|
+
exports.Md3Tab = Md3Tab;
|
|
93
|
+
exports.Md3TabPanel = Md3TabPanel;
|
|
94
|
+
exports.Md3Tabs = Md3Tabs;
|
|
95
|
+
exports.Md3TabsList = Md3TabsList;
|
|
96
|
+
//# sourceMappingURL=index.cjs.map
|
|
97
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","jsx","cn","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAM,WAAA,GAAoBA,+BAAuC,IAAI,CAAA;AACrE,IAAM,OAAA,GAAU,CAAC,CAAA,KAAc;AAC7B,EAAA,MAAM,GAAA,GAAYA,4BAAW,WAAW,CAAA;AACxC,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,4BAAA,CAA8B,CAAA;AAC5D,EAAA,OAAO,GAAA;AACT,CAAA;AASO,IAAM,OAAA,GAAgBA,gBAAA,CAAA,UAAA;AAAA,EAC3B,CAAC,EAAE,KAAA,EAAO,YAAA,EAAc,aAAA,EAAe,WAAW,QAAA,EAAU,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AAC9E,IAAA,MAAM,eAAe,KAAA,KAAU,MAAA;AAC/B,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAUA,0BAAS,YAAY,CAAA;AAC3D,IAAA,MAAM,OAAA,GAAU,eAAe,KAAA,GAAQ,QAAA;AACvC,IAAA,MAAM,QAAA,GAAW,CAAC,CAAA,KAAc;AAC9B,MAAA,IAAI,CAAC,YAAA,EAAc,WAAA,CAAY,CAAC,CAAA;AAChC,MAAA,aAAA,GAAgB,CAAC,CAAA;AAAA,IACnB,CAAA;AACA,IAAA,sCACG,KAAA,EAAA,EAAI,GAAA,EAAU,SAAA,EAAuB,GAAG,OACvC,QAAA,kBAAAC,cAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAO,EAAE,KAAA,EAAO,SAAS,QAAA,EAAS,EAAI,UAAS,CAAA,EACvE,CAAA;AAAA,E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S,CAAA;AAAA,UACpC,4BACCA,cAAA,CAAC,MAAA,EAAA,EAAK,aAAA,EAAW,IAAA,EAAC,WAAU,gFAAA,EAAiF;AAAA;AAAA;AAAA,KAEjH;AAAA,EAEJ;AACF;AACA,MAAA,CAAO,WAAA,GAAc,QAAA;AAOd,IAAM,WAAA,GAAoBD,gBAAA,CAAA,UAAA;AAAA,EAC/B,CAAC,EAAE,KAAA,EAAO,WAAW,GAAG,KAAA,IAAS,GAAA,KAAQ;AACvC,IAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAO,GAAI,QAAQ,aAAa,CAAA;AAC/C,IAAA,IAAI,MAAA,KAAW,OAAO,OAAO,IAAA;AAC7B,IAAA,uBAAOC,cAAA,CAAC,KAAA,EAAA,EAAI,GAAA,EAAU,IAAA,EAAK,UAAA,EAAW,SAAA,EAAWC,QAAA,CAAG,wBAAA,EAA0B,SAAS,CAAA,EAAI,GAAG,KAAA,EAAO,CAAA;AAAA,EACvG;AACF;AACA,WAAA,CAAY,WAAA,GAAc,aAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface TabsContextValue {\n value: string | undefined;\n setValue: (v: string) => void;\n}\nconst TabsContext = React.createContext<TabsContextValue | null>(null);\nconst useTabs = (c: string) => {\n const ctx = React.useContext(TabsContext);\n if (!ctx) throw new Error(`${c} must be used within Md3Tabs`);\n return ctx;\n};\n\nexport interface Md3TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"defaultValue\"> {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n}\n\n/** Material Design 3 primary tabs. Compose Md3TabsList, Md3Tab, Md3TabPanel. */\nexport const Md3Tabs = React.forwardRef<HTMLDivElement, Md3TabsProps>(\n ({ value, defaultValue, onValueChange, className, children, ...props }, ref) => {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState(defaultValue);\n const current = isControlled ? value : internal;\n const setValue = (v: string) => {\n if (!isControlled) setInternal(v);\n onValueChange?.(v);\n };\n return (\n <div ref={ref} className={className} {...props}>\n <TabsContext.Provider value={{ value: current, setValue }}>{children}</TabsContext.Provider>\n </div>\n );\n },\n);\nMd3Tabs.displayName = \"Md3Tabs\";\n\nexport const Md3TabsList = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div ref={ref} role=\"tablist\" className={cn(\"flex border-b border-md-surface-variant bg-md-surface\", className)} {...props} />\n ),\n);\nMd3TabsList.displayName = \"Md3TabsList\";\n\nexport interface Md3TabProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n value: string;\n icon?: React.ReactNode;\n}\n\n/** A single tab. */\nexport const Md3Tab = React.forwardRef<HTMLButtonElement, Md3TabProps>(\n ({ value, icon, className, children, ...props }, ref) => {\n const { value: active, setValue } = useTabs(\"Md3Tab\");\n const selected = active === value;\n return (\n <button\n ref={ref}\n type=\"button\"\n role=\"tab\"\n aria-selected={selected}\n onClick={() => setValue(value)}\n className={cn(\n \"relative inline-flex h-12 flex-1 items-center justify-center gap-2 overflow-hidden px-4 text-sm font-medium transition-colors [&_svg]:size-5\",\n \"before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:content-['']\",\n \"hover:before:opacity-[0.08] focus-visible:before:opacity-[0.12]\",\n \"outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-md-primary\",\n selected ? \"text-md-primary\" : \"text-md-on-surface-variant\",\n className,\n )}\n {...props}\n >\n {icon && <span className=\"relative\">{icon}</span>}\n <span className=\"relative\">{children}</span>\n {selected && (\n <span aria-hidden className=\"absolute inset-x-0 bottom-0 mx-auto h-[3px] w-3/5 rounded-t-full bg-md-primary\" />\n )}\n </button>\n );\n },\n);\nMd3Tab.displayName = \"Md3Tab\";\n\nexport interface Md3TabPanelProps extends React.HTMLAttributes<HTMLDivElement> {\n value: string;\n}\n\n/** The panel shown for the active tab. */\nexport const Md3TabPanel = React.forwardRef<HTMLDivElement, Md3TabPanelProps>(\n ({ value, className, ...props }, ref) => {\n const { value: active } = useTabs(\"Md3TabPanel\");\n if (active !== value) return null;\n return <div ref={ref} role=\"tabpanel\" className={cn(\"p-4 text-md-on-surface\", className)} {...props} />;\n },\n);\nMd3TabPanel.displayName = \"Md3TabPanel\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface Md3TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue"> {
|
|
4
|
+
value?: string;
|
|
5
|
+
defaultValue?: string;
|
|
6
|
+
onValueChange?: (value: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/** Material Design 3 primary tabs. Compose Md3TabsList, Md3Tab, Md3TabPanel. */
|
|
9
|
+
declare const Md3Tabs: React.ForwardRefExoticComponent<Md3TabsProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
declare const Md3TabsList: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
interface Md3TabProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
12
|
+
value: string;
|
|
13
|
+
icon?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/** A single tab. */
|
|
16
|
+
declare const Md3Tab: React.ForwardRefExoticComponent<Md3TabProps & React.RefAttributes<HTMLButtonElement>>;
|
|
17
|
+
interface Md3TabPanelProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
/** The panel shown for the active tab. */
|
|
21
|
+
declare const Md3TabPanel: React.ForwardRefExoticComponent<Md3TabPanelProps & React.RefAttributes<HTMLDivElement>>;
|
|
22
|
+
|
|
23
|
+
export { Md3Tab, Md3TabPanel, type Md3TabPanelProps, type Md3TabProps, Md3Tabs, Md3TabsList, type Md3TabsProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface Md3TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue"> {
|
|
4
|
+
value?: string;
|
|
5
|
+
defaultValue?: string;
|
|
6
|
+
onValueChange?: (value: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/** Material Design 3 primary tabs. Compose Md3TabsList, Md3Tab, Md3TabPanel. */
|
|
9
|
+
declare const Md3Tabs: React.ForwardRefExoticComponent<Md3TabsProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
declare const Md3TabsList: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
interface Md3TabProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
12
|
+
value: string;
|
|
13
|
+
icon?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/** A single tab. */
|
|
16
|
+
declare const Md3Tab: React.ForwardRefExoticComponent<Md3TabProps & React.RefAttributes<HTMLButtonElement>>;
|
|
17
|
+
interface Md3TabPanelProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
/** The panel shown for the active tab. */
|
|
21
|
+
declare const Md3TabPanel: React.ForwardRefExoticComponent<Md3TabPanelProps & React.RefAttributes<HTMLDivElement>>;
|
|
22
|
+
|
|
23
|
+
export { Md3Tab, Md3TabPanel, type Md3TabPanelProps, type Md3TabProps, Md3Tabs, Md3TabsList, type Md3TabsProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cn } from '@nucleux/utils';
|
|
4
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/index.tsx
|
|
7
|
+
var TabsContext = React.createContext(null);
|
|
8
|
+
var useTabs = (c) => {
|
|
9
|
+
const ctx = React.useContext(TabsContext);
|
|
10
|
+
if (!ctx) throw new Error(`${c} must be used within Md3Tabs`);
|
|
11
|
+
return ctx;
|
|
12
|
+
};
|
|
13
|
+
var Md3Tabs = React.forwardRef(
|
|
14
|
+
({ value, defaultValue, onValueChange, className, children, ...props }, ref) => {
|
|
15
|
+
const isControlled = value !== void 0;
|
|
16
|
+
const [internal, setInternal] = React.useState(defaultValue);
|
|
17
|
+
const current = isControlled ? value : internal;
|
|
18
|
+
const setValue = (v) => {
|
|
19
|
+
if (!isControlled) setInternal(v);
|
|
20
|
+
onValueChange?.(v);
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ jsx("div", { ref, className, ...props, children: /* @__PURE__ */ jsx(TabsContext.Provider, { value: { value: current, setValue }, children }) });
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
Md3Tabs.displayName = "Md3Tabs";
|
|
26
|
+
var Md3TabsList = React.forwardRef(
|
|
27
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, role: "tablist", className: cn("flex border-b border-md-surface-variant bg-md-surface", className), ...props })
|
|
28
|
+
);
|
|
29
|
+
Md3TabsList.displayName = "Md3TabsList";
|
|
30
|
+
var Md3Tab = React.forwardRef(
|
|
31
|
+
({ value, icon, className, children, ...props }, ref) => {
|
|
32
|
+
const { value: active, setValue } = useTabs("Md3Tab");
|
|
33
|
+
const selected = active === value;
|
|
34
|
+
return /* @__PURE__ */ jsxs(
|
|
35
|
+
"button",
|
|
36
|
+
{
|
|
37
|
+
ref,
|
|
38
|
+
type: "button",
|
|
39
|
+
role: "tab",
|
|
40
|
+
"aria-selected": selected,
|
|
41
|
+
onClick: () => setValue(value),
|
|
42
|
+
className: cn(
|
|
43
|
+
"relative inline-flex h-12 flex-1 items-center justify-center gap-2 overflow-hidden px-4 text-sm font-medium transition-colors [&_svg]:size-5",
|
|
44
|
+
"before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:content-['']",
|
|
45
|
+
"hover:before:opacity-[0.08] focus-visible:before:opacity-[0.12]",
|
|
46
|
+
"outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-md-primary",
|
|
47
|
+
selected ? "text-md-primary" : "text-md-on-surface-variant",
|
|
48
|
+
className
|
|
49
|
+
),
|
|
50
|
+
...props,
|
|
51
|
+
children: [
|
|
52
|
+
icon && /* @__PURE__ */ jsx("span", { className: "relative", children: icon }),
|
|
53
|
+
/* @__PURE__ */ jsx("span", { className: "relative", children }),
|
|
54
|
+
selected && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "absolute inset-x-0 bottom-0 mx-auto h-[3px] w-3/5 rounded-t-full bg-md-primary" })
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
Md3Tab.displayName = "Md3Tab";
|
|
61
|
+
var Md3TabPanel = React.forwardRef(
|
|
62
|
+
({ value, className, ...props }, ref) => {
|
|
63
|
+
const { value: active } = useTabs("Md3TabPanel");
|
|
64
|
+
if (active !== value) return null;
|
|
65
|
+
return /* @__PURE__ */ jsx("div", { ref, role: "tabpanel", className: cn("p-4 text-md-on-surface", className), ...props });
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
Md3TabPanel.displayName = "Md3TabPanel";
|
|
69
|
+
|
|
70
|
+
export { Md3Tab, Md3TabPanel, Md3Tabs, Md3TabsList };
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;AAOA,IAAM,WAAA,GAAoB,oBAAuC,IAAI,CAAA;AACrE,IAAM,OAAA,GAAU,CAAC,CAAA,KAAc;AAC7B,EAAA,MAAM,GAAA,GAAY,iBAAW,WAAW,CAAA;AACxC,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,CAAA,EA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EAAI,GAAA,EAAU,IAAA,EAAK,UAAA,EAAW,SAAA,EAAW,EAAA,CAAG,wBAAA,EAA0B,SAAS,CAAA,EAAI,GAAG,KAAA,EAAO,CAAA;AAAA,EACvG;AACF;AACA,WAAA,CAAY,WAAA,GAAc,aAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface TabsContextValue {\n value: string | undefined;\n setValue: (v: string) => void;\n}\nconst TabsContext = React.createContext<TabsContextValue | null>(null);\nconst useTabs = (c: string) => {\n const ctx = React.useContext(TabsContext);\n if (!ctx) throw new Error(`${c} must be used within Md3Tabs`);\n return ctx;\n};\n\nexport interface Md3TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"defaultValue\"> {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n}\n\n/** Material Design 3 primary tabs. Compose Md3TabsList, Md3Tab, Md3TabPanel. */\nexport const Md3Tabs = React.forwardRef<HTMLDivElement, Md3TabsProps>(\n ({ value, defaultValue, onValueChange, className, children, ...props }, ref) => {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState(defaultValue);\n const current = isControlled ? value : internal;\n const setValue = (v: string) => {\n if (!isControlled) setInternal(v);\n onValueChange?.(v);\n };\n return (\n <div ref={ref} className={className} {...props}>\n <TabsContext.Provider value={{ value: current, setValue }}>{children}</TabsContext.Provider>\n </div>\n );\n },\n);\nMd3Tabs.displayName = \"Md3Tabs\";\n\nexport const Md3TabsList = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div ref={ref} role=\"tablist\" className={cn(\"flex border-b border-md-surface-variant bg-md-surface\", className)} {...props} />\n ),\n);\nMd3TabsList.displayName = \"Md3TabsList\";\n\nexport interface Md3TabProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n value: string;\n icon?: React.ReactNode;\n}\n\n/** A single tab. */\nexport const Md3Tab = React.forwardRef<HTMLButtonElement, Md3TabProps>(\n ({ value, icon, className, children, ...props }, ref) => {\n const { value: active, setValue } = useTabs(\"Md3Tab\");\n const selected = active === value;\n return (\n <button\n ref={ref}\n type=\"button\"\n role=\"tab\"\n aria-selected={selected}\n onClick={() => setValue(value)}\n className={cn(\n \"relative inline-flex h-12 flex-1 items-center justify-center gap-2 overflow-hidden px-4 text-sm font-medium transition-colors [&_svg]:size-5\",\n \"before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:content-['']\",\n \"hover:before:opacity-[0.08] focus-visible:before:opacity-[0.12]\",\n \"outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-md-primary\",\n selected ? \"text-md-primary\" : \"text-md-on-surface-variant\",\n className,\n )}\n {...props}\n >\n {icon && <span className=\"relative\">{icon}</span>}\n <span className=\"relative\">{children}</span>\n {selected && (\n <span aria-hidden className=\"absolute inset-x-0 bottom-0 mx-auto h-[3px] w-3/5 rounded-t-full bg-md-primary\" />\n )}\n </button>\n );\n },\n);\nMd3Tab.displayName = \"Md3Tab\";\n\nexport interface Md3TabPanelProps extends React.HTMLAttributes<HTMLDivElement> {\n value: string;\n}\n\n/** The panel shown for the active tab. */\nexport const Md3TabPanel = React.forwardRef<HTMLDivElement, Md3TabPanelProps>(\n ({ value, className, ...props }, ref) => {\n const { value: active } = useTabs(\"Md3TabPanel\");\n if (active !== value) return null;\n return <div ref={ref} role=\"tabpanel\" className={cn(\"p-4 text-md-on-surface\", className)} {...props} />;\n },\n);\nMd3TabPanel.displayName = \"Md3TabPanel\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/md3-tabs",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Material 3 primary tabs — Nucleux agentic UI for React.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"nucleux",
|
|
9
|
+
"react",
|
|
10
|
+
"ui",
|
|
11
|
+
"components",
|
|
12
|
+
"agentic",
|
|
13
|
+
"ai",
|
|
14
|
+
"tailwind",
|
|
15
|
+
"md3-tabs"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=18",
|
|
33
|
+
"react-dom": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@nucleux/utils": "0.3.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"tsup": "^8.3.5",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"@types/react": "^18.3.18",
|
|
42
|
+
"react": "^18.3.1",
|
|
43
|
+
"lucide-react": "^0.469.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
52
|
+
"directory": "packages/md3-tabs"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup"
|
|
57
|
+
}
|
|
58
|
+
}
|