@codefast/ui 0.0.11 → 0.0.13
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/button.d.mts +1 -1
- package/dist/button.d.ts +1 -1
- package/dist/command.d.mts +15 -15
- package/dist/command.d.ts +15 -15
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +1 -8
- package/dist/segmented.d.mts +0 -22
- package/dist/segmented.d.ts +0 -22
- package/dist/segmented.js +0 -126
- package/dist/segmented.js.map +0 -1
- package/dist/segmented.mjs +0 -126
- package/dist/segmented.mjs.map +0 -1
- package/src/segmented.tsx +0 -176
package/dist/segmented.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkG3NP7M2Njs = require('./chunk-G3NP7M2N.js');
|
|
5
|
-
|
|
6
|
-
// src/segmented.tsx
|
|
7
|
-
var _react = require('react'); var React = _interopRequireWildcard(_react);
|
|
8
|
-
var _reacttogglegroup = require('@radix-ui/react-toggle-group'); var ToggleGroupPrimitive = _interopRequireWildcard(_reacttogglegroup);
|
|
9
|
-
var _reactusecontrollablestate = require('@radix-ui/react-use-controllable-state');
|
|
10
|
-
var _reactcontext = require('@radix-ui/react-context');
|
|
11
|
-
var _primitive = require('@radix-ui/primitive');
|
|
12
|
-
var _jsxruntime = require('react/jsx-runtime');
|
|
13
|
-
var SEGMENTED_NAME = "Segmented";
|
|
14
|
-
var [createSegmentedContext] = _reactcontext.createContextScope.call(void 0, SEGMENTED_NAME);
|
|
15
|
-
var [SegmentedProvider, useSegmentedContext] = createSegmentedContext(SEGMENTED_NAME);
|
|
16
|
-
var Segmented = React.forwardRef(
|
|
17
|
-
({
|
|
18
|
-
__scopeSegmented,
|
|
19
|
-
children,
|
|
20
|
-
className,
|
|
21
|
-
value: valueProp,
|
|
22
|
-
onValueChange: onValueChangeProp,
|
|
23
|
-
defaultValue: defaultValueProp,
|
|
24
|
-
...props
|
|
25
|
-
}, ref) => {
|
|
26
|
-
const [value, setValue] = _reactusecontrollablestate.useControllableState.call(void 0, {
|
|
27
|
-
prop: valueProp,
|
|
28
|
-
onChange: onValueChangeProp,
|
|
29
|
-
defaultProp: defaultValueProp
|
|
30
|
-
});
|
|
31
|
-
const childCount = React.Children.count(children);
|
|
32
|
-
const [offset, setOffset] = React.useState({
|
|
33
|
-
left: 0,
|
|
34
|
-
top: 0
|
|
35
|
-
});
|
|
36
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SegmentedProvider, { scope: __scopeSegmented, offset, setOffset, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
37
|
-
ToggleGroupPrimitive.Root,
|
|
38
|
-
{
|
|
39
|
-
ref,
|
|
40
|
-
className: _chunkG3NP7M2Njs.cn.call(void 0,
|
|
41
|
-
"bg-background relative isolate inline-grid h-10 min-w-max auto-cols-fr grid-flow-col items-stretch rounded-md border text-center align-top shadow-sm",
|
|
42
|
-
className
|
|
43
|
-
),
|
|
44
|
-
value,
|
|
45
|
-
onValueChange: (valueChanged) => {
|
|
46
|
-
if (valueChanged) {
|
|
47
|
-
setValue(valueChanged);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
type: "single",
|
|
51
|
-
...props,
|
|
52
|
-
style: {
|
|
53
|
-
"--offset-left": `${offset.left.toString()}px`,
|
|
54
|
-
"--offset-top": `${offset.top.toString()}px`,
|
|
55
|
-
...props.style
|
|
56
|
-
},
|
|
57
|
-
children: [
|
|
58
|
-
children,
|
|
59
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
60
|
-
"div",
|
|
61
|
-
{
|
|
62
|
-
className: _chunkG3NP7M2Njs.cn.call(void 0,
|
|
63
|
-
"pointer-events-none absolute -z-[1] h-full translate-x-[var(--offset-left)] transition-transform",
|
|
64
|
-
"before:bg-accent before:absolute before:inset-0 before:rounded"
|
|
65
|
-
),
|
|
66
|
-
style: {
|
|
67
|
-
width: `calc(100% / ${childCount.toString()})`
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
)
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
) });
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
Segmented.displayName = SEGMENTED_NAME;
|
|
77
|
-
var SEGMENTED_ITEM_NAME = "SegmentedItem";
|
|
78
|
-
var SegmentedItem = React.forwardRef(
|
|
79
|
-
({ __scopeSegmented, children, className, onClick, ...props }, ref) => {
|
|
80
|
-
const { setOffset } = useSegmentedContext(SEGMENTED_ITEM_NAME, __scopeSegmented);
|
|
81
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
82
|
-
ToggleGroupPrimitive.Item,
|
|
83
|
-
{
|
|
84
|
-
ref,
|
|
85
|
-
className: _chunkG3NP7M2Njs.cn.call(void 0,
|
|
86
|
-
"group flex select-none items-stretch rounded text-sm first:rounded-l-[inherit] [&:nth-last-child(2)]:rounded-r-[inherit]",
|
|
87
|
-
"hover:bg-accent/30",
|
|
88
|
-
"group-aria-checked:text-accent-foreground",
|
|
89
|
-
className
|
|
90
|
-
),
|
|
91
|
-
onClick: _primitive.composeEventHandlers.call(void 0, onClick, (event) => {
|
|
92
|
-
setOffset({
|
|
93
|
-
left: event.currentTarget.offsetLeft,
|
|
94
|
-
top: event.currentTarget.offsetTop
|
|
95
|
-
});
|
|
96
|
-
}),
|
|
97
|
-
...props,
|
|
98
|
-
children: [
|
|
99
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
100
|
-
"span",
|
|
101
|
-
{
|
|
102
|
-
className: _chunkG3NP7M2Njs.cn.call(void 0,
|
|
103
|
-
"bg-border my-1.5 w-px transition",
|
|
104
|
-
"group-first:opacity-0",
|
|
105
|
-
"group-[:where([data-state=on])+*]:opacity-0 group-aria-checked:opacity-0",
|
|
106
|
-
"group-focus-visible:opacity-0 group-[&:focus-visible+*]:opacity-0",
|
|
107
|
-
"group-[:where([data-state=on])+*]:scale-0 group-aria-checked:scale-0",
|
|
108
|
-
"group-focus-visible:scale-0 group-[&:focus-visible+*]:scale-0"
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
),
|
|
112
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex grow items-center justify-center gap-2 px-3 py-1 [&_svg]:shrink-0", children: [
|
|
113
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "font-medium opacity-0 transition-opacity group-aria-checked:opacity-100", children }),
|
|
114
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "absolute opacity-100 transition-opacity group-aria-checked:opacity-0", children })
|
|
115
|
-
] })
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
SegmentedItem.displayName = SEGMENTED_ITEM_NAME;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
exports.Segmented = Segmented; exports.SegmentedItem = SegmentedItem;
|
|
126
|
-
//# sourceMappingURL=segmented.js.map
|
package/dist/segmented.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/segmented.tsx"],"names":[],"mappings":";;;;;;AAEA,YAAY,WAAW;AACvB,YAAY,0BAA0B;AACtC,SAAS,4BAA4B;AACrC,SAAS,0BAAsC;AAC/C,SAAS,4BAA4B;AA+D7B,SAuBE,KAvBF;AAtDR,IAAM,iBAAiB;AAIvB,IAAM,CAAC,sBAAsB,IAAI,mBAAmB,cAAc;AAYlE,IAAM,CAAC,mBAAmB,mBAAmB,IAAI,uBAA8C,cAAc;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U,IAAI,oBAAoB,qBAAqB,gBAAgB;AAE/E,WACE;AAAA,MAAsB;AAAA,MAArB;AAAA,QACC;AAAA,QACA,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA,SAAS,qBAAqB,SAAS,CAAC,UAAU;AAChD,oBAAU;AAAA,YACR,MAAM,MAAM,cAAc;AAAA,YAC1B,KAAK,MAAM,cAAc;AAAA,UAC3B,CAAC;AAAA,QACH,CAAC;AAAA,QACA,GAAG;AAAA,QAGJ;AAAA;AAAA,YAAC;AAAA;AAAA,cACC,WAAW;AAAA,gBACT;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA;AAAA,UACF;AAAA,UAEA,qBAAC,UAAK,WAAU,0EAEd;AAAA,gCAAC,UAAK,WAAU,2EAA2E,UAAS;AAAA,YAEpG,oBAAC,UAAK,WAAU,wEAAwE,UAAS;AAAA,aACnG;AAAA;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,cAAc,cAAc","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as ToggleGroupPrimitive from \"@radix-ui/react-toggle-group\";\nimport { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport { createContextScope, type Scope } from \"@radix-ui/react-context\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { cn } from \"./utils\";\n\ntype RemovedProps = \"value\" | \"asChild\" | \"defaultChecked\" | \"defaultValue\";\n\n/* -----------------------------------------------------------------------------\n * Component: Segmented\n * -------------------------------------------------------------------------- */\n\nconst SEGMENTED_NAME = \"Segmented\";\n\ntype ScopedProps<P> = P & { __scopeSegmented?: Scope };\n\nconst [createSegmentedContext] = createContextScope(SEGMENTED_NAME);\n\ninterface Offset {\n left: number;\n top: number;\n}\n\ninterface SegmentedContextValue {\n offset: Offset;\n setOffset: React.Dispatch<React.SetStateAction<Offset>>;\n}\n\nconst [SegmentedProvider, useSegmentedContext] = createSegmentedContext<SegmentedContextValue>(SEGMENTED_NAME);\n\ntype SegmentedElement = React.ElementRef<typeof ToggleGroupPrimitive.Root>;\ntype SegmentedProps = Omit<\n React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root>,\n RemovedProps | \"disabled\" | \"type\" | \"onValueChange\"\n> & {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n};\n\nconst Segmented = React.forwardRef<SegmentedElement, SegmentedProps>(\n (\n {\n __scopeSegmented,\n children,\n className,\n value: valueProp,\n onValueChange: onValueChangeProp,\n defaultValue: defaultValueProp,\n ...props\n }: ScopedProps<SegmentedProps>,\n ref,\n ) => {\n const [value, setValue] = useControllableState({\n prop: valueProp,\n onChange: onValueChangeProp,\n defaultProp: defaultValueProp,\n });\n const childCount = React.Children.count(children);\n const [offset, setOffset] = React.useState<Offset>({\n left: 0,\n top: 0,\n });\n\n return (\n <SegmentedProvider scope={__scopeSegmented} offset={offset} setOffset={setOffset}>\n <ToggleGroupPrimitive.Root\n ref={ref}\n className={cn(\n \"bg-background relative isolate inline-grid h-10 min-w-max auto-cols-fr grid-flow-col items-stretch rounded-md border text-center align-top shadow-sm\",\n className,\n )}\n value={value}\n onValueChange={(valueChanged) => {\n if (valueChanged) {\n setValue(valueChanged);\n }\n }}\n type=\"single\"\n {...props}\n style={\n {\n \"--offset-left\": `${offset.left.toString()}px`,\n \"--offset-top\": `${offset.top.toString()}px`,\n ...props.style,\n } as React.CSSProperties\n }\n >\n {children}\n <div\n className={cn(\n \"pointer-events-none absolute -z-[1] h-full translate-x-[var(--offset-left)] transition-transform\",\n \"before:bg-accent before:absolute before:inset-0 before:rounded\",\n )}\n style={\n {\n width: `calc(100% / ${childCount.toString()})`,\n } as React.CSSProperties\n }\n />\n </ToggleGroupPrimitive.Root>\n </SegmentedProvider>\n );\n },\n);\n\nSegmented.displayName = SEGMENTED_NAME;\n\n/* -----------------------------------------------------------------------------\n * Component: SegmentedItem\n * -------------------------------------------------------------------------- */\n\nconst SEGMENTED_ITEM_NAME = \"SegmentedItem\";\n\ntype SegmentedItemElement = React.ElementRef<typeof ToggleGroupPrimitive.Item>;\ntype SegmentedItemProps = Omit<\n React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item>,\n RemovedProps | \"disabled\" | \"type\"\n> & {\n value: string;\n};\n\nconst SegmentedItem = React.forwardRef<SegmentedItemElement, SegmentedItemProps>(\n ({ __scopeSegmented, children, className, onClick, ...props }: ScopedProps<SegmentedItemProps>, ref) => {\n const { setOffset } = useSegmentedContext(SEGMENTED_ITEM_NAME, __scopeSegmented);\n\n return (\n <ToggleGroupPrimitive.Item\n ref={ref}\n className={cn(\n \"group flex select-none items-stretch rounded text-sm first:rounded-l-[inherit] [&:nth-last-child(2)]:rounded-r-[inherit]\",\n \"hover:bg-accent/30\",\n \"group-aria-checked:text-accent-foreground\",\n className,\n )}\n onClick={composeEventHandlers(onClick, (event) => {\n setOffset({\n left: event.currentTarget.offsetLeft,\n top: event.currentTarget.offsetTop,\n });\n })}\n {...props}\n >\n {/* Separator */}\n <span\n className={cn(\n \"bg-border my-1.5 w-px transition\",\n \"group-first:opacity-0\",\n \"group-[:where([data-state=on])+*]:opacity-0 group-aria-checked:opacity-0\",\n \"group-focus-visible:opacity-0 group-[&:focus-visible+*]:opacity-0\",\n \"group-[:where([data-state=on])+*]:scale-0 group-aria-checked:scale-0\",\n \"group-focus-visible:scale-0 group-[&:focus-visible+*]:scale-0\",\n )}\n />\n {/* Label */}\n <span className=\"flex grow items-center justify-center gap-2 px-3 py-1 [&_svg]:shrink-0\">\n {/* LabelActive */}\n <span className=\"font-medium opacity-0 transition-opacity group-aria-checked:opacity-100\">{children}</span>\n {/* LabelInactive */}\n <span className=\"absolute opacity-100 transition-opacity group-aria-checked:opacity-0\">{children}</span>\n </span>\n </ToggleGroupPrimitive.Item>\n );\n },\n);\n\nSegmentedItem.displayName = SEGMENTED_ITEM_NAME;\n\n/* -----------------------------------------------------------------------------\n * Exports\n * -------------------------------------------------------------------------- */\n\nexport { Segmented, SegmentedItem, type SegmentedProps, type SegmentedItemProps };\n"]}
|
package/dist/segmented.mjs
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
cn
|
|
4
|
-
} from "./chunk-UG3URV2Z.mjs";
|
|
5
|
-
|
|
6
|
-
// src/segmented.tsx
|
|
7
|
-
import * as React from "react";
|
|
8
|
-
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
|
|
9
|
-
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
10
|
-
import { createContextScope } from "@radix-ui/react-context";
|
|
11
|
-
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
12
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
-
var SEGMENTED_NAME = "Segmented";
|
|
14
|
-
var [createSegmentedContext] = createContextScope(SEGMENTED_NAME);
|
|
15
|
-
var [SegmentedProvider, useSegmentedContext] = createSegmentedContext(SEGMENTED_NAME);
|
|
16
|
-
var Segmented = React.forwardRef(
|
|
17
|
-
({
|
|
18
|
-
__scopeSegmented,
|
|
19
|
-
children,
|
|
20
|
-
className,
|
|
21
|
-
value: valueProp,
|
|
22
|
-
onValueChange: onValueChangeProp,
|
|
23
|
-
defaultValue: defaultValueProp,
|
|
24
|
-
...props
|
|
25
|
-
}, ref) => {
|
|
26
|
-
const [value, setValue] = useControllableState({
|
|
27
|
-
prop: valueProp,
|
|
28
|
-
onChange: onValueChangeProp,
|
|
29
|
-
defaultProp: defaultValueProp
|
|
30
|
-
});
|
|
31
|
-
const childCount = React.Children.count(children);
|
|
32
|
-
const [offset, setOffset] = React.useState({
|
|
33
|
-
left: 0,
|
|
34
|
-
top: 0
|
|
35
|
-
});
|
|
36
|
-
return /* @__PURE__ */ jsx(SegmentedProvider, { scope: __scopeSegmented, offset, setOffset, children: /* @__PURE__ */ jsxs(
|
|
37
|
-
ToggleGroupPrimitive.Root,
|
|
38
|
-
{
|
|
39
|
-
ref,
|
|
40
|
-
className: cn(
|
|
41
|
-
"bg-background relative isolate inline-grid h-10 min-w-max auto-cols-fr grid-flow-col items-stretch rounded-md border text-center align-top shadow-sm",
|
|
42
|
-
className
|
|
43
|
-
),
|
|
44
|
-
value,
|
|
45
|
-
onValueChange: (valueChanged) => {
|
|
46
|
-
if (valueChanged) {
|
|
47
|
-
setValue(valueChanged);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
type: "single",
|
|
51
|
-
...props,
|
|
52
|
-
style: {
|
|
53
|
-
"--offset-left": `${offset.left.toString()}px`,
|
|
54
|
-
"--offset-top": `${offset.top.toString()}px`,
|
|
55
|
-
...props.style
|
|
56
|
-
},
|
|
57
|
-
children: [
|
|
58
|
-
children,
|
|
59
|
-
/* @__PURE__ */ jsx(
|
|
60
|
-
"div",
|
|
61
|
-
{
|
|
62
|
-
className: cn(
|
|
63
|
-
"pointer-events-none absolute -z-[1] h-full translate-x-[var(--offset-left)] transition-transform",
|
|
64
|
-
"before:bg-accent before:absolute before:inset-0 before:rounded"
|
|
65
|
-
),
|
|
66
|
-
style: {
|
|
67
|
-
width: `calc(100% / ${childCount.toString()})`
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
)
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
) });
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
Segmented.displayName = SEGMENTED_NAME;
|
|
77
|
-
var SEGMENTED_ITEM_NAME = "SegmentedItem";
|
|
78
|
-
var SegmentedItem = React.forwardRef(
|
|
79
|
-
({ __scopeSegmented, children, className, onClick, ...props }, ref) => {
|
|
80
|
-
const { setOffset } = useSegmentedContext(SEGMENTED_ITEM_NAME, __scopeSegmented);
|
|
81
|
-
return /* @__PURE__ */ jsxs(
|
|
82
|
-
ToggleGroupPrimitive.Item,
|
|
83
|
-
{
|
|
84
|
-
ref,
|
|
85
|
-
className: cn(
|
|
86
|
-
"group flex select-none items-stretch rounded text-sm first:rounded-l-[inherit] [&:nth-last-child(2)]:rounded-r-[inherit]",
|
|
87
|
-
"hover:bg-accent/30",
|
|
88
|
-
"group-aria-checked:text-accent-foreground",
|
|
89
|
-
className
|
|
90
|
-
),
|
|
91
|
-
onClick: composeEventHandlers(onClick, (event) => {
|
|
92
|
-
setOffset({
|
|
93
|
-
left: event.currentTarget.offsetLeft,
|
|
94
|
-
top: event.currentTarget.offsetTop
|
|
95
|
-
});
|
|
96
|
-
}),
|
|
97
|
-
...props,
|
|
98
|
-
children: [
|
|
99
|
-
/* @__PURE__ */ jsx(
|
|
100
|
-
"span",
|
|
101
|
-
{
|
|
102
|
-
className: cn(
|
|
103
|
-
"bg-border my-1.5 w-px transition",
|
|
104
|
-
"group-first:opacity-0",
|
|
105
|
-
"group-[:where([data-state=on])+*]:opacity-0 group-aria-checked:opacity-0",
|
|
106
|
-
"group-focus-visible:opacity-0 group-[&:focus-visible+*]:opacity-0",
|
|
107
|
-
"group-[:where([data-state=on])+*]:scale-0 group-aria-checked:scale-0",
|
|
108
|
-
"group-focus-visible:scale-0 group-[&:focus-visible+*]:scale-0"
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
),
|
|
112
|
-
/* @__PURE__ */ jsxs("span", { className: "flex grow items-center justify-center gap-2 px-3 py-1 [&_svg]:shrink-0", children: [
|
|
113
|
-
/* @__PURE__ */ jsx("span", { className: "font-medium opacity-0 transition-opacity group-aria-checked:opacity-100", children }),
|
|
114
|
-
/* @__PURE__ */ jsx("span", { className: "absolute opacity-100 transition-opacity group-aria-checked:opacity-0", children })
|
|
115
|
-
] })
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
SegmentedItem.displayName = SEGMENTED_ITEM_NAME;
|
|
122
|
-
export {
|
|
123
|
-
Segmented,
|
|
124
|
-
SegmentedItem
|
|
125
|
-
};
|
|
126
|
-
//# sourceMappingURL=segmented.mjs.map
|
package/dist/segmented.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/segmented.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as ToggleGroupPrimitive from \"@radix-ui/react-toggle-group\";\nimport { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport { createContextScope, type Scope } from \"@radix-ui/react-context\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { cn } from \"./utils\";\n\ntype RemovedProps = \"value\" | \"asChild\" | \"defaultChecked\" | \"defaultValue\";\n\n/* -----------------------------------------------------------------------------\n * Component: Segmented\n * -------------------------------------------------------------------------- */\n\nconst SEGMENTED_NAME = \"Segmented\";\n\ntype ScopedProps<P> = P & { __scopeSegmented?: Scope };\n\nconst [createSegmentedContext] = createContextScope(SEGMENTED_NAME);\n\ninterface Offset {\n left: number;\n top: number;\n}\n\ninterface SegmentedContextValue {\n offset: Offset;\n setOffset: React.Dispatch<React.SetStateAction<Offset>>;\n}\n\nconst [SegmentedProvider, useSegmentedContext] = createSegmentedContext<SegmentedContextValue>(SEGMENTED_NAME);\n\ntype SegmentedElement = React.ElementRef<typeof ToggleGroupPrimitive.Root>;\ntype SegmentedProps = Omit<\n React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root>,\n RemovedProps | \"disabled\" | \"type\" | \"onValueChange\"\n> & {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n};\n\nconst Segmented = React.forwardRef<SegmentedElement, SegmentedProps>(\n (\n {\n __scopeSegmented,\n children,\n className,\n value: valueProp,\n onValueChange: onValueChangeProp,\n defaultValue: defaultValueProp,\n ...props\n }: ScopedProps<SegmentedProps>,\n ref,\n ) => {\n const [value, setValue] = useControllableState({\n prop: valueProp,\n onChange: onValueChangeProp,\n defaultProp: defaultValueProp,\n });\n const childCount = React.Children.count(children);\n const [offset, setOffset] = React.useState<Offset>({\n left: 0,\n top: 0,\n });\n\n return (\n <SegmentedProvider scope={__scopeSegmented} offset={offset} setOffset={setOffset}>\n <ToggleGroupPrimitive.Root\n ref={ref}\n className={cn(\n \"bg-background relative isolate inline-grid h-10 min-w-max auto-cols-fr grid-flow-col items-stretch rounded-md border text-center align-top shadow-sm\",\n className,\n )}\n value={value}\n onValueChange={(valueChanged) => {\n if (valueChanged) {\n setValue(valueChanged);\n }\n }}\n type=\"single\"\n {...props}\n style={\n {\n \"--offset-left\": `${offset.left.toString()}px`,\n \"--offset-top\": `${offset.top.toString()}px`,\n ...props.style,\n } as React.CSSProperties\n }\n >\n {children}\n <div\n className={cn(\n \"pointer-events-none absolute -z-[1] h-full translate-x-[var(--offset-left)] transition-transform\",\n \"before:bg-accent before:absolute before:inset-0 before:rounded\",\n )}\n style={\n {\n width: `calc(100% / ${childCount.toString()})`,\n } as React.CSSProperties\n }\n />\n </ToggleGroupPrimitive.Root>\n </SegmentedProvider>\n );\n },\n);\n\nSegmented.displayName = SEGMENTED_NAME;\n\n/* -----------------------------------------------------------------------------\n * Component: SegmentedItem\n * -------------------------------------------------------------------------- */\n\nconst SEGMENTED_ITEM_NAME = \"SegmentedItem\";\n\ntype SegmentedItemElement = React.ElementRef<typeof ToggleGroupPrimitive.Item>;\ntype SegmentedItemProps = Omit<\n React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item>,\n RemovedProps | \"disabled\" | \"type\"\n> & {\n value: string;\n};\n\nconst SegmentedItem = React.forwardRef<SegmentedItemElement, SegmentedItemProps>(\n ({ __scopeSegmented, children, className, onClick, ...props }: ScopedProps<SegmentedItemProps>, ref) => {\n const { setOffset } = useSegmentedContext(SEGMENTED_ITEM_NAME, __scopeSegmented);\n\n return (\n <ToggleGroupPrimitive.Item\n ref={ref}\n className={cn(\n \"group flex select-none items-stretch rounded text-sm first:rounded-l-[inherit] [&:nth-last-child(2)]:rounded-r-[inherit]\",\n \"hover:bg-accent/30\",\n \"group-aria-checked:text-accent-foreground\",\n className,\n )}\n onClick={composeEventHandlers(onClick, (event) => {\n setOffset({\n left: event.currentTarget.offsetLeft,\n top: event.currentTarget.offsetTop,\n });\n })}\n {...props}\n >\n {/* Separator */}\n <span\n className={cn(\n \"bg-border my-1.5 w-px transition\",\n \"group-first:opacity-0\",\n \"group-[:where([data-state=on])+*]:opacity-0 group-aria-checked:opacity-0\",\n \"group-focus-visible:opacity-0 group-[&:focus-visible+*]:opacity-0\",\n \"group-[:where([data-state=on])+*]:scale-0 group-aria-checked:scale-0\",\n \"group-focus-visible:scale-0 group-[&:focus-visible+*]:scale-0\",\n )}\n />\n {/* Label */}\n <span className=\"flex grow items-center justify-center gap-2 px-3 py-1 [&_svg]:shrink-0\">\n {/* LabelActive */}\n <span className=\"font-medium opacity-0 transition-opacity group-aria-checked:opacity-100\">{children}</span>\n {/* LabelInactive */}\n <span className=\"absolute opacity-100 transition-opacity group-aria-checked:opacity-0\">{children}</span>\n </span>\n </ToggleGroupPrimitive.Item>\n );\n },\n);\n\nSegmentedItem.displayName = SEGMENTED_ITEM_NAME;\n\n/* -----------------------------------------------------------------------------\n * Exports\n * -------------------------------------------------------------------------- */\n\nexport { Segmented, SegmentedItem, type SegmentedProps, type SegmentedItemProps };\n"],"mappings":";;;;;;AAEA,YAAY,WAAW;AACvB,YAAY,0BAA0B;AACtC,SAAS,4BAA4B;AACrC,SAAS,0BAAsC;AAC/C,SAAS,4BAA4B;AA+D7B,SAuBE,KAvBF;AAtDR,IAAM,iBAAiB;AAIvB,IAAM,CAAC,sBAAsB,IAAI,mBAAmB,cAAc;AAYlE,IAAM,CAAC,mBAAmB,mBAAmB,IAAI,uBAA8C,cAAc;AAY7G,IAAM,YAAkB;AAAA,EACtB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,eAAe;AAAA,IACf,cAAc;AAAA,IACd,GAAG;AAAA,EACL,GACA,QACG;AACH,UAAM,CAAC,OAAO,QAAQ,IAAI,qBAAqB;AAAA,MAC7C,MAAM;AAAA,MACN,UAAU;AAA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A,YAC1B,KAAK,MAAM,cAAc;AAAA,UAC3B,CAAC;AAAA,QACH,CAAC;AAAA,QACA,GAAG;AAAA,QAGJ;AAAA;AAAA,YAAC;AAAA;AAAA,cACC,WAAW;AAAA,gBACT;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA;AAAA,UACF;AAAA,UAEA,qBAAC,UAAK,WAAU,0EAEd;AAAA,gCAAC,UAAK,WAAU,2EAA2E,UAAS;AAAA,YAEpG,oBAAC,UAAK,WAAU,wEAAwE,UAAS;AAAA,aACnG;AAAA;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,cAAc,cAAc;","names":[]}
|
package/src/segmented.tsx
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
|
|
5
|
-
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
6
|
-
import { createContextScope, type Scope } from "@radix-ui/react-context";
|
|
7
|
-
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
8
|
-
import { cn } from "./utils";
|
|
9
|
-
|
|
10
|
-
type RemovedProps = "value" | "asChild" | "defaultChecked" | "defaultValue";
|
|
11
|
-
|
|
12
|
-
/* -----------------------------------------------------------------------------
|
|
13
|
-
* Component: Segmented
|
|
14
|
-
* -------------------------------------------------------------------------- */
|
|
15
|
-
|
|
16
|
-
const SEGMENTED_NAME = "Segmented";
|
|
17
|
-
|
|
18
|
-
type ScopedProps<P> = P & { __scopeSegmented?: Scope };
|
|
19
|
-
|
|
20
|
-
const [createSegmentedContext] = createContextScope(SEGMENTED_NAME);
|
|
21
|
-
|
|
22
|
-
interface Offset {
|
|
23
|
-
left: number;
|
|
24
|
-
top: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface SegmentedContextValue {
|
|
28
|
-
offset: Offset;
|
|
29
|
-
setOffset: React.Dispatch<React.SetStateAction<Offset>>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const [SegmentedProvider, useSegmentedContext] = createSegmentedContext<SegmentedContextValue>(SEGMENTED_NAME);
|
|
33
|
-
|
|
34
|
-
type SegmentedElement = React.ElementRef<typeof ToggleGroupPrimitive.Root>;
|
|
35
|
-
type SegmentedProps = Omit<
|
|
36
|
-
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root>,
|
|
37
|
-
RemovedProps | "disabled" | "type" | "onValueChange"
|
|
38
|
-
> & {
|
|
39
|
-
value?: string;
|
|
40
|
-
defaultValue?: string;
|
|
41
|
-
onValueChange?: (value: string) => void;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const Segmented = React.forwardRef<SegmentedElement, SegmentedProps>(
|
|
45
|
-
(
|
|
46
|
-
{
|
|
47
|
-
__scopeSegmented,
|
|
48
|
-
children,
|
|
49
|
-
className,
|
|
50
|
-
value: valueProp,
|
|
51
|
-
onValueChange: onValueChangeProp,
|
|
52
|
-
defaultValue: defaultValueProp,
|
|
53
|
-
...props
|
|
54
|
-
}: ScopedProps<SegmentedProps>,
|
|
55
|
-
ref,
|
|
56
|
-
) => {
|
|
57
|
-
const [value, setValue] = useControllableState({
|
|
58
|
-
prop: valueProp,
|
|
59
|
-
onChange: onValueChangeProp,
|
|
60
|
-
defaultProp: defaultValueProp,
|
|
61
|
-
});
|
|
62
|
-
const childCount = React.Children.count(children);
|
|
63
|
-
const [offset, setOffset] = React.useState<Offset>({
|
|
64
|
-
left: 0,
|
|
65
|
-
top: 0,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<SegmentedProvider scope={__scopeSegmented} offset={offset} setOffset={setOffset}>
|
|
70
|
-
<ToggleGroupPrimitive.Root
|
|
71
|
-
ref={ref}
|
|
72
|
-
className={cn(
|
|
73
|
-
"bg-background relative isolate inline-grid h-10 min-w-max auto-cols-fr grid-flow-col items-stretch rounded-md border text-center align-top shadow-sm",
|
|
74
|
-
className,
|
|
75
|
-
)}
|
|
76
|
-
value={value}
|
|
77
|
-
onValueChange={(valueChanged) => {
|
|
78
|
-
if (valueChanged) {
|
|
79
|
-
setValue(valueChanged);
|
|
80
|
-
}
|
|
81
|
-
}}
|
|
82
|
-
type="single"
|
|
83
|
-
{...props}
|
|
84
|
-
style={
|
|
85
|
-
{
|
|
86
|
-
"--offset-left": `${offset.left.toString()}px`,
|
|
87
|
-
"--offset-top": `${offset.top.toString()}px`,
|
|
88
|
-
...props.style,
|
|
89
|
-
} as React.CSSProperties
|
|
90
|
-
}
|
|
91
|
-
>
|
|
92
|
-
{children}
|
|
93
|
-
<div
|
|
94
|
-
className={cn(
|
|
95
|
-
"pointer-events-none absolute -z-[1] h-full translate-x-[var(--offset-left)] transition-transform",
|
|
96
|
-
"before:bg-accent before:absolute before:inset-0 before:rounded",
|
|
97
|
-
)}
|
|
98
|
-
style={
|
|
99
|
-
{
|
|
100
|
-
width: `calc(100% / ${childCount.toString()})`,
|
|
101
|
-
} as React.CSSProperties
|
|
102
|
-
}
|
|
103
|
-
/>
|
|
104
|
-
</ToggleGroupPrimitive.Root>
|
|
105
|
-
</SegmentedProvider>
|
|
106
|
-
);
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
Segmented.displayName = SEGMENTED_NAME;
|
|
111
|
-
|
|
112
|
-
/* -----------------------------------------------------------------------------
|
|
113
|
-
* Component: SegmentedItem
|
|
114
|
-
* -------------------------------------------------------------------------- */
|
|
115
|
-
|
|
116
|
-
const SEGMENTED_ITEM_NAME = "SegmentedItem";
|
|
117
|
-
|
|
118
|
-
type SegmentedItemElement = React.ElementRef<typeof ToggleGroupPrimitive.Item>;
|
|
119
|
-
type SegmentedItemProps = Omit<
|
|
120
|
-
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item>,
|
|
121
|
-
RemovedProps | "disabled" | "type"
|
|
122
|
-
> & {
|
|
123
|
-
value: string;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const SegmentedItem = React.forwardRef<SegmentedItemElement, SegmentedItemProps>(
|
|
127
|
-
({ __scopeSegmented, children, className, onClick, ...props }: ScopedProps<SegmentedItemProps>, ref) => {
|
|
128
|
-
const { setOffset } = useSegmentedContext(SEGMENTED_ITEM_NAME, __scopeSegmented);
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
<ToggleGroupPrimitive.Item
|
|
132
|
-
ref={ref}
|
|
133
|
-
className={cn(
|
|
134
|
-
"group flex select-none items-stretch rounded text-sm first:rounded-l-[inherit] [&:nth-last-child(2)]:rounded-r-[inherit]",
|
|
135
|
-
"hover:bg-accent/30",
|
|
136
|
-
"group-aria-checked:text-accent-foreground",
|
|
137
|
-
className,
|
|
138
|
-
)}
|
|
139
|
-
onClick={composeEventHandlers(onClick, (event) => {
|
|
140
|
-
setOffset({
|
|
141
|
-
left: event.currentTarget.offsetLeft,
|
|
142
|
-
top: event.currentTarget.offsetTop,
|
|
143
|
-
});
|
|
144
|
-
})}
|
|
145
|
-
{...props}
|
|
146
|
-
>
|
|
147
|
-
{/* Separator */}
|
|
148
|
-
<span
|
|
149
|
-
className={cn(
|
|
150
|
-
"bg-border my-1.5 w-px transition",
|
|
151
|
-
"group-first:opacity-0",
|
|
152
|
-
"group-[:where([data-state=on])+*]:opacity-0 group-aria-checked:opacity-0",
|
|
153
|
-
"group-focus-visible:opacity-0 group-[&:focus-visible+*]:opacity-0",
|
|
154
|
-
"group-[:where([data-state=on])+*]:scale-0 group-aria-checked:scale-0",
|
|
155
|
-
"group-focus-visible:scale-0 group-[&:focus-visible+*]:scale-0",
|
|
156
|
-
)}
|
|
157
|
-
/>
|
|
158
|
-
{/* Label */}
|
|
159
|
-
<span className="flex grow items-center justify-center gap-2 px-3 py-1 [&_svg]:shrink-0">
|
|
160
|
-
{/* LabelActive */}
|
|
161
|
-
<span className="font-medium opacity-0 transition-opacity group-aria-checked:opacity-100">{children}</span>
|
|
162
|
-
{/* LabelInactive */}
|
|
163
|
-
<span className="absolute opacity-100 transition-opacity group-aria-checked:opacity-0">{children}</span>
|
|
164
|
-
</span>
|
|
165
|
-
</ToggleGroupPrimitive.Item>
|
|
166
|
-
);
|
|
167
|
-
},
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
SegmentedItem.displayName = SEGMENTED_ITEM_NAME;
|
|
171
|
-
|
|
172
|
-
/* -----------------------------------------------------------------------------
|
|
173
|
-
* Exports
|
|
174
|
-
* -------------------------------------------------------------------------- */
|
|
175
|
-
|
|
176
|
-
export { Segmented, SegmentedItem, type SegmentedProps, type SegmentedItemProps };
|