@rubenpazch/segmented-control 0.0.0-stage → 0.1.1
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/README.md +32 -2
- package/dist/SegmentedControl.d.ts +30 -0
- package/dist/SegmentedControl.d.ts.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +75 -3
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rubenpazch/segmented-control
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- catalogo:inicio (generado por pnpm catalogo, no editar) -->
|
|
4
|
+
|
|
5
|
+
Botones unidos para elegir una opción entre pocas (radiogroup con flechas del teclado): Personal | Empresa, Mes | Año.
|
|
6
|
+
|
|
7
|
+
- **Usar cuando:** Cambiar la vista o un filtro con 2 a 5 opciones cortas, siempre visibles.
|
|
8
|
+
- **Evitar cuando:** Opciones largas o dentro de un formulario con etiqueta: usa RadioGroup. Muchas opciones: usa Select.
|
|
9
|
+
|
|
10
|
+
Se recomienda instalar el paquete completo `@rubenpazch/ui` (incluye este). Por separado:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @rubenpazch/segmented-control
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## SegmentedControl
|
|
17
|
+
|
|
18
|
+
Selector de una opción entre pocas, como botones unidos (role="radiogroup"). Se mueve con
|
|
19
|
+
las flechas del teclado. Ej.: Personal | Empresa, Mes | Año.
|
|
20
|
+
|
|
21
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
22
|
+
| ------------ | ---------------------- | ---- | ----------- | ---------------------------------------------- |
|
|
23
|
+
| `aria-label` | `string` | sí | | Nombre accesible del grupo: "Ámbito", "Vista". |
|
|
24
|
+
| `onChange` | `(value: T) => void` | sí | | Recibe el valor elegido. |
|
|
25
|
+
| `options` | `SegmentedOption<T>[]` | sí | | Opciones (2 a 5 funcionan mejor). |
|
|
26
|
+
| `value` | `string` | sí | | Valor seleccionado. |
|
|
27
|
+
| `className` | `string` | | | Clase extra. |
|
|
28
|
+
| `fullWidth` | `boolean` | | `false` | Ocupa todo el ancho. |
|
|
29
|
+
| `size` | `"sm" \| "md"` | | `md` | sm o md (por defecto). |
|
|
30
|
+
|
|
31
|
+
Tipos: `SegmentedControlProps`, `SegmentedOption`.
|
|
32
|
+
|
|
33
|
+
<!-- catalogo:fin -->
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface SegmentedOption<T extends string = string> {
|
|
3
|
+
value: T;
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
/** Icono opcional antes del texto. */
|
|
6
|
+
icon?: React.ReactNode;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SegmentedControlProps<T extends string = string> {
|
|
10
|
+
/** Opciones (2 a 5 funcionan mejor). */
|
|
11
|
+
options: SegmentedOption<T>[];
|
|
12
|
+
/** Valor seleccionado. */
|
|
13
|
+
value: T;
|
|
14
|
+
/** Recibe el valor elegido. */
|
|
15
|
+
onChange: (value: T) => void;
|
|
16
|
+
/** Nombre accesible del grupo: "Ámbito", "Vista". */
|
|
17
|
+
"aria-label": string;
|
|
18
|
+
/** sm o md (por defecto). */
|
|
19
|
+
size?: "sm" | "md";
|
|
20
|
+
/** Ocupa todo el ancho. */
|
|
21
|
+
fullWidth?: boolean;
|
|
22
|
+
/** Clase extra. */
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Selector de una opción entre pocas, como botones unidos (role="radiogroup"). Se mueve con
|
|
27
|
+
* las flechas del teclado. Ej.: Personal | Empresa, Mes | Año.
|
|
28
|
+
*/
|
|
29
|
+
export default function SegmentedControl<T extends string = string>({ options, value, onChange, "aria-label": ariaLabel, size, fullWidth, className, }: SegmentedControlProps<T>): React.JSX.Element;
|
|
30
|
+
//# sourceMappingURL=SegmentedControl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../src/SegmentedControl.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAGtC,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACxD,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,sCAAsC;IACtC,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC9D,wCAAwC;IACxC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9B,0BAA0B;IAC1B,KAAK,EAAE,CAAC,CAAC;IACT,+BAA+B;IAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAClE,OAAO,EACP,KAAK,EACL,QAAQ,EACR,YAAY,EAAE,SAAS,EACvB,IAAW,EACX,SAAiB,EACjB,SAAS,GACV,EAAE,qBAAqB,CAAC,CAAC,CAAC,qBA6D1B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),n=require("react");var o={group:"SegmentedControl-module_group__JB8MS",full:"SegmentedControl-module_full__RsbjG",segment:"SegmentedControl-module_segment__LfuIs",md:"SegmentedControl-module_md__qiYE5",sm:"SegmentedControl-module_sm__026JT",selected:"SegmentedControl-module_selected__FrZM9",icon:"SegmentedControl-module_icon__XoZaG"};!function(e,n){void 0===n&&(n={});var o=n.insertAt;if("undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],l=document.createElement("style");l.type="text/css","top"===o&&t.firstChild?t.insertBefore(l,t.firstChild):t.appendChild(l),l.styleSheet?l.styleSheet.cssText=e:l.appendChild(document.createTextNode(e))}}(".SegmentedControl-module_group__JB8MS {\n display: inline-flex;\n gap: 2px;\n padding: 3px;\n border-radius: var(--lb-radius-lg);\n background: var(--lb-color-muted);\n font-family: var(--lb-font-sans);\n}\n\n.SegmentedControl-module_full__RsbjG {\n display: flex;\n width: 100%;\n}\n\n.SegmentedControl-module_full__RsbjG .SegmentedControl-module_segment__LfuIs {\n flex: 1;\n}\n\n.SegmentedControl-module_segment__LfuIs {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: var(--lb-space-1);\n border: 0;\n border-radius: var(--lb-radius-md);\n background: transparent;\n color: var(--lb-color-muted-foreground);\n font: inherit;\n font-weight: var(--lb-font-weight-medium);\n white-space: nowrap;\n cursor: pointer;\n transition: background 120ms ease, color 120ms ease;\n}\n\n.SegmentedControl-module_md__qiYE5 .SegmentedControl-module_segment__LfuIs { padding: var(--lb-space-2) var(--lb-space-4); font-size: var(--lb-font-size-sm); }\n.SegmentedControl-module_sm__026JT .SegmentedControl-module_segment__LfuIs { padding: var(--lb-space-1) var(--lb-space-3); font-size: var(--lb-font-size-xs); }\n\n.SegmentedControl-module_segment__LfuIs:hover:not(:disabled) {\n color: var(--lb-color-foreground);\n}\n\n.SegmentedControl-module_segment__LfuIs:focus-visible {\n outline: 2px solid var(--lb-color-ring);\n outline-offset: 1px;\n}\n\n.SegmentedControl-module_segment__LfuIs:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.SegmentedControl-module_selected__FrZM9 {\n background: var(--lb-color-background);\n color: var(--lb-color-foreground);\n box-shadow: var(--lb-shadow-sm);\n}\n\n.SegmentedControl-module_icon__XoZaG {\n display: inline-flex;\n}\n");const t=(...e)=>e.filter(Boolean).join(" ");module.exports=function({options:l,value:r,onChange:d,"aria-label":a,size:s="md",fullWidth:i=!1,className:u}){const m=n.useRef([]),c=l.map((e,n)=>({o:e,i:n})).filter(({o:e})=>!e.disabled),_=(e,n)=>{const o=c.findIndex(({i:n})=>n===e),t=c[(o+n+c.length)%c.length];t&&(d(t.o.value),m.current[t.i]?.focus())};return e.jsx("div",{role:"radiogroup","aria-label":a,className:t(o.group,o[s],i&&o.full,u),children:l.map((n,l)=>{const a=n.value===r;return e.jsxs("button",{ref:e=>{m.current[l]=e},type:"button",role:"radio","aria-checked":a,tabIndex:a?0:-1,disabled:n.disabled,onClick:()=>d(n.value),onKeyDown:e=>{"ArrowRight"===e.key||"ArrowDown"===e.key?(e.preventDefault(),_(l,1)):"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(e.preventDefault(),_(l,-1))},className:t(o.segment,a&&o.selected),children:[n.icon&&e.jsx("span",{className:o.icon,"aria-hidden":"true",children:n.icon}),n.label]},n.value)})})};
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/SegmentedControl.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React, { useRef } from \"react\";\nimport styles from \"./SegmentedControl.module.css\";\n\nexport interface SegmentedOption<T extends string = string> {\n value: T;\n label: React.ReactNode;\n /** Icono opcional antes del texto. */\n icon?: React.ReactNode;\n disabled?: boolean;\n}\n\nexport interface SegmentedControlProps<T extends string = string> {\n /** Opciones (2 a 5 funcionan mejor). */\n options: SegmentedOption<T>[];\n /** Valor seleccionado. */\n value: T;\n /** Recibe el valor elegido. */\n onChange: (value: T) => void;\n /** Nombre accesible del grupo: \"Ámbito\", \"Vista\". */\n \"aria-label\": string;\n /** sm o md (por defecto). */\n size?: \"sm\" | \"md\";\n /** Ocupa todo el ancho. */\n fullWidth?: boolean;\n /** Clase extra. */\n className?: string;\n}\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/**\n * Selector de una opción entre pocas, como botones unidos (role=\"radiogroup\"). Se mueve con\n * las flechas del teclado. Ej.: Personal | Empresa, Mes | Año.\n */\nexport default function SegmentedControl<T extends string = string>({\n options,\n value,\n onChange,\n \"aria-label\": ariaLabel,\n size = \"md\",\n fullWidth = false,\n className,\n}: SegmentedControlProps<T>) {\n const refs = useRef<Array<HTMLButtonElement | null>>([]);\n const enabled = options\n .map((o, i) => ({ o, i }))\n .filter(({ o }) => !o.disabled);\n\n const move = (from: number, delta: number) => {\n const pos = enabled.findIndex(({ i }) => i === from);\n const next = enabled[(pos + delta + enabled.length) % enabled.length];\n if (!next) return;\n onChange(next.o.value);\n refs.current[next.i]?.focus();\n };\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n className={cx(\n styles.group,\n styles[size],\n fullWidth && styles.full,\n className,\n )}\n >\n {options.map((opt, i) => {\n const selected = opt.value === value;\n return (\n <button\n key={opt.value}\n ref={(el) => {\n refs.current[i] = el;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={selected}\n tabIndex={selected ? 0 : -1}\n disabled={opt.disabled}\n onClick={() => onChange(opt.value)}\n onKeyDown={(e) => {\n if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n e.preventDefault();\n move(i, 1);\n } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n move(i, -1);\n }\n }}\n className={cx(styles.segment, selected && styles.selected)}\n >\n {opt.icon && (\n <span className={styles.icon} aria-hidden=\"true\">\n {opt.icon}\n </span>\n )}\n {opt.label}\n </button>\n );\n })}\n </div>\n );\n}\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","options","value","onChange","ariaLabel","size","fullWidth","className","refs","useRef","enabled","map","o","i","disabled","move","from","delta","pos","findIndex","next","length","current","focus","_jsx","role","styles","group","full","children","opt","selected","_jsxs","el","tabIndex","onClick","onKeyDown","e","key","preventDefault","segment","icon","label"],"mappings":"iYAAA,SAAqBA,EAAKC,YACnBA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBW,CAqBzD,msDCGA,MAAMe,EAAK,IAAIC,IACbA,EAAEC,OAAOC,SAASC,KAAK,oBAMX,UAAsDC,QAClEA,EAAOC,MACPA,EAAKC,SACLA,EACA,aAAcC,EAASC,KACvBA,EAAO,KAAIC,UACX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';
|
|
2
|
+
|
|
3
|
+
interface SegmentedOption<T extends string = string> {
|
|
4
|
+
value: T;
|
|
5
|
+
label: React.ReactNode;
|
|
6
|
+
/** Icono opcional antes del texto. */
|
|
7
|
+
icon?: React.ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface SegmentedControlProps<T extends string = string> {
|
|
11
|
+
/** Opciones (2 a 5 funcionan mejor). */
|
|
12
|
+
options: SegmentedOption<T>[];
|
|
13
|
+
/** Valor seleccionado. */
|
|
14
|
+
value: T;
|
|
15
|
+
/** Recibe el valor elegido. */
|
|
16
|
+
onChange: (value: T) => void;
|
|
17
|
+
/** Nombre accesible del grupo: "Ámbito", "Vista". */
|
|
18
|
+
"aria-label": string;
|
|
19
|
+
/** sm o md (por defecto). */
|
|
20
|
+
size?: "sm" | "md";
|
|
21
|
+
/** Ocupa todo el ancho. */
|
|
22
|
+
fullWidth?: boolean;
|
|
23
|
+
/** Clase extra. */
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Selector de una opción entre pocas, como botones unidos (role="radiogroup"). Se mueve con
|
|
28
|
+
* las flechas del teclado. Ej.: Personal | Empresa, Mes | Año.
|
|
29
|
+
*/
|
|
30
|
+
declare function SegmentedControl<T extends string = string>({ options, value, onChange, "aria-label": ariaLabel, size, fullWidth, className, }: SegmentedControlProps<T>): React.JSX.Element;
|
|
31
|
+
|
|
32
|
+
export { SegmentedControl as default };
|
|
33
|
+
export type { SegmentedControlProps, SegmentedOption };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,YAAY,EACV,qBAAqB,EACrB,eAAe,GAChB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{useRef as o}from"react";var t={group:"SegmentedControl-module_group__JB8MS",full:"SegmentedControl-module_full__RsbjG",segment:"SegmentedControl-module_segment__LfuIs",md:"SegmentedControl-module_md__qiYE5",sm:"SegmentedControl-module_sm__026JT",selected:"SegmentedControl-module_selected__FrZM9",icon:"SegmentedControl-module_icon__XoZaG"};!function(e,n){void 0===n&&(n={});var o=n.insertAt;if("undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],l=document.createElement("style");l.type="text/css","top"===o&&t.firstChild?t.insertBefore(l,t.firstChild):t.appendChild(l),l.styleSheet?l.styleSheet.cssText=e:l.appendChild(document.createTextNode(e))}}(".SegmentedControl-module_group__JB8MS {\n display: inline-flex;\n gap: 2px;\n padding: 3px;\n border-radius: var(--lb-radius-lg);\n background: var(--lb-color-muted);\n font-family: var(--lb-font-sans);\n}\n\n.SegmentedControl-module_full__RsbjG {\n display: flex;\n width: 100%;\n}\n\n.SegmentedControl-module_full__RsbjG .SegmentedControl-module_segment__LfuIs {\n flex: 1;\n}\n\n.SegmentedControl-module_segment__LfuIs {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: var(--lb-space-1);\n border: 0;\n border-radius: var(--lb-radius-md);\n background: transparent;\n color: var(--lb-color-muted-foreground);\n font: inherit;\n font-weight: var(--lb-font-weight-medium);\n white-space: nowrap;\n cursor: pointer;\n transition: background 120ms ease, color 120ms ease;\n}\n\n.SegmentedControl-module_md__qiYE5 .SegmentedControl-module_segment__LfuIs { padding: var(--lb-space-2) var(--lb-space-4); font-size: var(--lb-font-size-sm); }\n.SegmentedControl-module_sm__026JT .SegmentedControl-module_segment__LfuIs { padding: var(--lb-space-1) var(--lb-space-3); font-size: var(--lb-font-size-xs); }\n\n.SegmentedControl-module_segment__LfuIs:hover:not(:disabled) {\n color: var(--lb-color-foreground);\n}\n\n.SegmentedControl-module_segment__LfuIs:focus-visible {\n outline: 2px solid var(--lb-color-ring);\n outline-offset: 1px;\n}\n\n.SegmentedControl-module_segment__LfuIs:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n}\n\n.SegmentedControl-module_selected__FrZM9 {\n background: var(--lb-color-background);\n color: var(--lb-color-foreground);\n box-shadow: var(--lb-shadow-sm);\n}\n\n.SegmentedControl-module_icon__XoZaG {\n display: inline-flex;\n}\n");const l=(...e)=>e.filter(Boolean).join(" ");function r({options:r,value:d,onChange:a,"aria-label":s,size:i="md",fullWidth:m=!1,className:u}){const c=o([]),_=r.map((e,n)=>({o:e,i:n})).filter(({o:e})=>!e.disabled),g=(e,n)=>{const o=_.findIndex(({i:n})=>n===e),t=_[(o+n+_.length)%_.length];t&&(a(t.o.value),c.current[t.i]?.focus())};return e("div",{role:"radiogroup","aria-label":s,className:l(t.group,t[i],m&&t.full,u),children:r.map((o,r)=>{const s=o.value===d;return n("button",{ref:e=>{c.current[r]=e},type:"button",role:"radio","aria-checked":s,tabIndex:s?0:-1,disabled:o.disabled,onClick:()=>a(o.value),onKeyDown:e=>{"ArrowRight"===e.key||"ArrowDown"===e.key?(e.preventDefault(),g(r,1)):"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(e.preventDefault(),g(r,-1))},className:l(t.segment,s&&t.selected),children:[o.icon&&e("span",{className:t.icon,"aria-hidden":"true",children:o.icon}),o.label]},o.value)})})}export{r as default};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/SegmentedControl.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React, { useRef } from \"react\";\nimport styles from \"./SegmentedControl.module.css\";\n\nexport interface SegmentedOption<T extends string = string> {\n value: T;\n label: React.ReactNode;\n /** Icono opcional antes del texto. */\n icon?: React.ReactNode;\n disabled?: boolean;\n}\n\nexport interface SegmentedControlProps<T extends string = string> {\n /** Opciones (2 a 5 funcionan mejor). */\n options: SegmentedOption<T>[];\n /** Valor seleccionado. */\n value: T;\n /** Recibe el valor elegido. */\n onChange: (value: T) => void;\n /** Nombre accesible del grupo: \"Ámbito\", \"Vista\". */\n \"aria-label\": string;\n /** sm o md (por defecto). */\n size?: \"sm\" | \"md\";\n /** Ocupa todo el ancho. */\n fullWidth?: boolean;\n /** Clase extra. */\n className?: string;\n}\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/**\n * Selector de una opción entre pocas, como botones unidos (role=\"radiogroup\"). Se mueve con\n * las flechas del teclado. Ej.: Personal | Empresa, Mes | Año.\n */\nexport default function SegmentedControl<T extends string = string>({\n options,\n value,\n onChange,\n \"aria-label\": ariaLabel,\n size = \"md\",\n fullWidth = false,\n className,\n}: SegmentedControlProps<T>) {\n const refs = useRef<Array<HTMLButtonElement | null>>([]);\n const enabled = options\n .map((o, i) => ({ o, i }))\n .filter(({ o }) => !o.disabled);\n\n const move = (from: number, delta: number) => {\n const pos = enabled.findIndex(({ i }) => i === from);\n const next = enabled[(pos + delta + enabled.length) % enabled.length];\n if (!next) return;\n onChange(next.o.value);\n refs.current[next.i]?.focus();\n };\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n className={cx(\n styles.group,\n styles[size],\n fullWidth && styles.full,\n className,\n )}\n >\n {options.map((opt, i) => {\n const selected = opt.value === value;\n return (\n <button\n key={opt.value}\n ref={(el) => {\n refs.current[i] = el;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={selected}\n tabIndex={selected ? 0 : -1}\n disabled={opt.disabled}\n onClick={() => onChange(opt.value)}\n onKeyDown={(e) => {\n if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n e.preventDefault();\n move(i, 1);\n } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n move(i, -1);\n }\n }}\n className={cx(styles.segment, selected && styles.selected)}\n >\n {opt.icon && (\n <span className={styles.icon} aria-hidden=\"true\">\n {opt.icon}\n </span>\n )}\n {opt.label}\n </button>\n );\n })}\n </div>\n );\n}\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","SegmentedControl","options","value","onChange","ariaLabel","size","fullWidth","className","refs","useRef","enabled","map","o","i","disabled","move","from","delta","pos","findIndex","next","length","current","focus","_jsx","role","styles","group","full","children","opt","selected","_jsxs","el","tabIndex","onClick","onKeyDown","e","key","preventDefault","segment","icon","label"],"mappings":"+YAAA,SAAqBA,EAAKC,YACnBA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBW,CAqBzD,msDCGA,MAAMe,EAAK,IAAIC,IACbA,EAAEC,OAAOC,SAASC,KAAK,KAMX,SAAUC,GAA4CC,QAClEA,EAAOC,MACPA,EAAKC,SACLA,EACA,aAAcC,EAASC,KACvBA,EAAO,KAAIC,UACXA,GAAY,EAAKC,UACjBA,IA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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Selector de una opción entre pocas como botones unidos",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rubenpazch/lbyte-ui-library.git",
|
|
8
|
+
"directory": "packages/segmented-control"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.cjs.js",
|
|
12
|
+
"module": "dist/index.esm.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.esm.js",
|
|
18
|
+
"require": "./dist/index.cjs.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"**/*.css"
|
|
26
|
+
],
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": "^19.2.3",
|
|
29
|
+
"react-dom": "^19.2.3",
|
|
30
|
+
"@rubenpazch/tokens": "0.5.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@rubenpazch/shared": "5.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
37
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
38
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
39
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
40
|
+
"@testing-library/react": "^16.3.3",
|
|
41
|
+
"@types/jest": "^30.0.0",
|
|
42
|
+
"@types/react": "^19.2.18",
|
|
43
|
+
"@types/react-dom": "^19.2.5",
|
|
44
|
+
"autoprefixer": "^10.5.4",
|
|
45
|
+
"eslint": "^9.39.5",
|
|
46
|
+
"identity-obj-proxy": "^3.0.0",
|
|
47
|
+
"jest": "^30.5.0",
|
|
48
|
+
"jest-environment-jsdom": "^30.5.0",
|
|
49
|
+
"postcss": "^8.5.26",
|
|
50
|
+
"prettier": "^3.9.6",
|
|
51
|
+
"react": "^19.2.8",
|
|
52
|
+
"react-dom": "^19.2.8",
|
|
53
|
+
"rollup": "^4.63.1",
|
|
54
|
+
"rollup-plugin-dts": "^6.5.1",
|
|
55
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
56
|
+
"rollup-plugin-typescript2": "^0.37.0",
|
|
57
|
+
"tslib": "^2.8.1",
|
|
58
|
+
"typescript": "^6.0.3",
|
|
59
|
+
"@rubenpazch/eslint-config": "4.0.0",
|
|
60
|
+
"@rubenpazch/typescript-config": "3.0.0"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"lbyte": {
|
|
66
|
+
"categoria": "formularios",
|
|
67
|
+
"resumen": "Botones unidos para elegir una opción entre pocas (radiogroup con flechas del teclado): Personal | Empresa, Mes | Año.",
|
|
68
|
+
"usarCuando": "Cambiar la vista o un filtro con 2 a 5 opciones cortas, siempre visibles.",
|
|
69
|
+
"evitarCuando": "Opciones largas o dentro de un formulario con etiqueta: usa RadioGroup. Muchas opciones: usa Select."
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "rollup -c",
|
|
73
|
+
"test": "jest --passWithNoTests",
|
|
74
|
+
"test:watch": "jest --watch",
|
|
75
|
+
"lint": "eslint src",
|
|
76
|
+
"clean": "rm -rf dist"
|
|
77
|
+
}
|
|
6
78
|
}
|