@economic/taco 9.0.1-taco-docs-publishing.0 → 10.0.0-docs-publishing.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/components/Actions/Link/Link.cjs +1 -1
- package/dist/components/Actions/Link/Link.cjs.map +1 -1
- package/dist/components/Actions/Link/Link.js +1 -1
- package/dist/components/Actions/Link/Link.js.map +1 -1
- package/dist/components/Hanger/Arrow.cjs +2 -3
- package/dist/components/Hanger/Arrow.cjs.map +1 -1
- package/dist/components/Hanger/Arrow.js +2 -2
- package/dist/components/Hanger/Arrow.js.map +1 -1
- package/dist/components/Hanger/Hanger.cjs +33 -41
- package/dist/components/Hanger/Hanger.cjs.map +1 -1
- package/dist/components/Hanger/Hanger.d.ts +2 -2
- package/dist/components/Hanger/Hanger.js +33 -40
- package/dist/components/Hanger/Hanger.js.map +1 -1
- package/dist/components/Select/useSelect.cjs.map +1 -1
- package/dist/components/Select/useSelect.d.ts +2 -2
- package/dist/components/Select/useSelect.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/taco.css +0 -38
- package/package.json +2 -3
- package/dist/components/Navigation/Navigation.cjs +0 -105
- package/dist/components/Navigation/Navigation.cjs.map +0 -1
- package/dist/components/Navigation/Navigation.d.ts +0 -49
- package/dist/components/Navigation/Navigation.js +0 -105
- package/dist/components/Navigation/Navigation.js.map +0 -1
|
@@ -35,7 +35,7 @@ function LinkInner(props, ref) {
|
|
|
35
35
|
size ? [typography.TYPOGRAPHY_TEXT_SIZE_CLASSES[size], typography.TYPOGRAPHY_LINE_HEIGHT_CLASSES[size]] : void 0,
|
|
36
36
|
/** set underline thickness depending on size of Link */
|
|
37
37
|
size === "sm" ? "decoration-1" : "decoration-2",
|
|
38
|
-
"underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 hover:text-blue-900 active:text-blue-900 visited:text-blue-700 underline-offset-2 ",
|
|
38
|
+
"underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 focus-visible:text-blue-700 hover:text-blue-900 focus-visible:hover:text-blue-900 active:text-blue-900 focus-visible:active:text-blue-900 visited:text-blue-700 focus-visible:visited:text-blue-700 underline-offset-2 ",
|
|
39
39
|
{
|
|
40
40
|
"font-bold": bold
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.cjs","sources":["../../../../src/components/Actions/Link/Link.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\n\nimport { TYPOGRAPHY_LINE_HEIGHT_CLASSES, TYPOGRAPHY_TEXT_SIZE_CLASSES } from '../../../utils/typography';\n\n/**\n * Link label: string text (literals, template literals, i18n helpers that return `string`, string constants),\n * or a single React element—typically a component whose output is text-only.\n * (TypeScript cannot enforce “component returns string” vs JSX; avoid non-text elements.)\n */\nexport type LinkChildren = string | React.ReactElement | null;\n\n/** Props specific to our Link component */\ntype LinkOwnProps<T extends React.ElementType = 'a'> = {\n /** Allows using a custom or framework-specific link component (e.g. Next.js or React Router) */\n as?: T;\n /** Set specific size that matches our text sizes. If it's not set, it inherits the parent size */\n size?: 'sm' | 'md' | 'lg';\n /** If true, the Link will be rendered in bold */\n bold?: boolean;\n /** The content of the Link */\n children?: LinkChildren;\n};\n\n/**\n * LinkProps combines our own props with the props of the underlying element (via `as`).\n * This allows the component to accept props like `to` for React Router or `href` for native anchors.\n * Note: `className` and `style` are explicitly excluded.\n */\nexport type LinkProps<T extends React.ElementType = 'a'> = LinkOwnProps<T> &\n Omit<React.ComponentPropsWithoutRef<T>, keyof LinkOwnProps<T> | 'className' | 'style'>;\n\nfunction LinkInner<T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> },\n ref: React.Ref<unknown>\n) {\n // Destructure and discard className/style to prevent them from being applied at runtime\n const {\n as,\n size,\n bold,\n children,\n className: _,\n style: __,\n ...otherProps\n } = props as LinkProps<T> & {\n className?: string;\n style?: React.CSSProperties;\n };\n\n const Component: React.ElementType = as || 'a';\n\n const className = cn(\n size ? [TYPOGRAPHY_TEXT_SIZE_CLASSES[size], TYPOGRAPHY_LINE_HEIGHT_CLASSES[size]] : undefined,\n /** set underline thickness depending on size of Link */\n size === 'sm' ? 'decoration-1' : 'decoration-2',\n 'underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 hover:text-blue-900 active:text-blue-900 visited:text-blue-700 underline-offset-2 ',\n {\n 'font-bold': bold,\n }\n );\n\n return (\n <Component {...otherProps} className={className} data-taco=\"link\" ref={ref}>\n {children}\n </Component>\n );\n}\n\nexport const Link = React.forwardRef(LinkInner) as <T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> }\n) => React.ReactElement | null;\n"],"names":["TYPOGRAPHY_TEXT_SIZE_CLASSES","TYPOGRAPHY_LINE_HEIGHT_CLASSES","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAS,UACL,OACA,KACF;AAEQ,QAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP,GAAG;AAAA,EAAA,IACH;AAKJ,QAAM,YAA+B,MAAM;AAE3C,QAAM,YAAY;AAAA,IACd,OAAO,CAACA,WAAAA,6BAA6B,IAAI,GAAGC,WAAAA,+BAA+B,IAAI,CAAC,IAAI;AAAA;AAAA,IAEpF,SAAS,OAAO,iBAAiB;AAAA,IACjC;AAAA,IACA;AAAA,MACI,aAAa;AAAA,IAAA;AAAA,EAErB;AAGI,SAAAC,iCAAA,cAAC,aAAW,GAAG,YAAY,WAAsB,aAAU,QAAO,OAC7D,QACL;AAER;AAEa,MAAA,OAAOA,iBAAM,WAAW,SAAS;;"}
|
|
1
|
+
{"version":3,"file":"Link.cjs","sources":["../../../../src/components/Actions/Link/Link.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\n\nimport { TYPOGRAPHY_LINE_HEIGHT_CLASSES, TYPOGRAPHY_TEXT_SIZE_CLASSES } from '../../../utils/typography';\n\n/**\n * Link label: string text (literals, template literals, i18n helpers that return `string`, string constants),\n * or a single React element—typically a component whose output is text-only.\n * (TypeScript cannot enforce “component returns string” vs JSX; avoid non-text elements.)\n */\nexport type LinkChildren = string | React.ReactElement | null;\n\n/** Props specific to our Link component */\ntype LinkOwnProps<T extends React.ElementType = 'a'> = {\n /** Allows using a custom or framework-specific link component (e.g. Next.js or React Router) */\n as?: T;\n /** Set specific size that matches our text sizes. If it's not set, it inherits the parent size */\n size?: 'sm' | 'md' | 'lg';\n /** If true, the Link will be rendered in bold */\n bold?: boolean;\n /** The content of the Link */\n children?: LinkChildren;\n};\n\n/**\n * LinkProps combines our own props with the props of the underlying element (via `as`).\n * This allows the component to accept props like `to` for React Router or `href` for native anchors.\n * Note: `className` and `style` are explicitly excluded.\n */\nexport type LinkProps<T extends React.ElementType = 'a'> = LinkOwnProps<T> &\n Omit<React.ComponentPropsWithoutRef<T>, keyof LinkOwnProps<T> | 'className' | 'style'>;\n\nfunction LinkInner<T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> },\n ref: React.Ref<unknown>\n) {\n // Destructure and discard className/style to prevent them from being applied at runtime\n const {\n as,\n size,\n bold,\n children,\n className: _,\n style: __,\n ...otherProps\n } = props as LinkProps<T> & {\n className?: string;\n style?: React.CSSProperties;\n };\n\n const Component: React.ElementType = as || 'a';\n\n const className = cn(\n size ? [TYPOGRAPHY_TEXT_SIZE_CLASSES[size], TYPOGRAPHY_LINE_HEIGHT_CLASSES[size]] : undefined,\n /** set underline thickness depending on size of Link */\n size === 'sm' ? 'decoration-1' : 'decoration-2',\n 'underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 focus-visible:text-blue-700 hover:text-blue-900 focus-visible:hover:text-blue-900 active:text-blue-900 focus-visible:active:text-blue-900 visited:text-blue-700 focus-visible:visited:text-blue-700 underline-offset-2 ',\n {\n 'font-bold': bold,\n }\n );\n\n return (\n <Component {...otherProps} className={className} data-taco=\"link\" ref={ref}>\n {children}\n </Component>\n );\n}\n\nexport const Link = React.forwardRef(LinkInner) as <T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> }\n) => React.ReactElement | null;\n"],"names":["TYPOGRAPHY_TEXT_SIZE_CLASSES","TYPOGRAPHY_LINE_HEIGHT_CLASSES","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAS,UACL,OACA,KACF;AAEQ,QAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP,GAAG;AAAA,EAAA,IACH;AAKJ,QAAM,YAA+B,MAAM;AAE3C,QAAM,YAAY;AAAA,IACd,OAAO,CAACA,WAAAA,6BAA6B,IAAI,GAAGC,WAAAA,+BAA+B,IAAI,CAAC,IAAI;AAAA;AAAA,IAEpF,SAAS,OAAO,iBAAiB;AAAA,IACjC;AAAA,IACA;AAAA,MACI,aAAa;AAAA,IAAA;AAAA,EAErB;AAGI,SAAAC,iCAAA,cAAC,aAAW,GAAG,YAAY,WAAsB,aAAU,QAAO,OAC7D,QACL;AAER;AAEa,MAAA,OAAOA,iBAAM,WAAW,SAAS;;"}
|
|
@@ -16,7 +16,7 @@ function LinkInner(props, ref) {
|
|
|
16
16
|
size ? [TYPOGRAPHY_TEXT_SIZE_CLASSES[size], TYPOGRAPHY_LINE_HEIGHT_CLASSES[size]] : void 0,
|
|
17
17
|
/** set underline thickness depending on size of Link */
|
|
18
18
|
size === "sm" ? "decoration-1" : "decoration-2",
|
|
19
|
-
"underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 hover:text-blue-900 active:text-blue-900 visited:text-blue-700 underline-offset-2 ",
|
|
19
|
+
"underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 focus-visible:text-blue-700 hover:text-blue-900 focus-visible:hover:text-blue-900 active:text-blue-900 focus-visible:active:text-blue-900 visited:text-blue-700 focus-visible:visited:text-blue-700 underline-offset-2 ",
|
|
20
20
|
{
|
|
21
21
|
"font-bold": bold
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","sources":["../../../../src/components/Actions/Link/Link.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\n\nimport { TYPOGRAPHY_LINE_HEIGHT_CLASSES, TYPOGRAPHY_TEXT_SIZE_CLASSES } from '../../../utils/typography';\n\n/**\n * Link label: string text (literals, template literals, i18n helpers that return `string`, string constants),\n * or a single React element—typically a component whose output is text-only.\n * (TypeScript cannot enforce “component returns string” vs JSX; avoid non-text elements.)\n */\nexport type LinkChildren = string | React.ReactElement | null;\n\n/** Props specific to our Link component */\ntype LinkOwnProps<T extends React.ElementType = 'a'> = {\n /** Allows using a custom or framework-specific link component (e.g. Next.js or React Router) */\n as?: T;\n /** Set specific size that matches our text sizes. If it's not set, it inherits the parent size */\n size?: 'sm' | 'md' | 'lg';\n /** If true, the Link will be rendered in bold */\n bold?: boolean;\n /** The content of the Link */\n children?: LinkChildren;\n};\n\n/**\n * LinkProps combines our own props with the props of the underlying element (via `as`).\n * This allows the component to accept props like `to` for React Router or `href` for native anchors.\n * Note: `className` and `style` are explicitly excluded.\n */\nexport type LinkProps<T extends React.ElementType = 'a'> = LinkOwnProps<T> &\n Omit<React.ComponentPropsWithoutRef<T>, keyof LinkOwnProps<T> | 'className' | 'style'>;\n\nfunction LinkInner<T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> },\n ref: React.Ref<unknown>\n) {\n // Destructure and discard className/style to prevent them from being applied at runtime\n const {\n as,\n size,\n bold,\n children,\n className: _,\n style: __,\n ...otherProps\n } = props as LinkProps<T> & {\n className?: string;\n style?: React.CSSProperties;\n };\n\n const Component: React.ElementType = as || 'a';\n\n const className = cn(\n size ? [TYPOGRAPHY_TEXT_SIZE_CLASSES[size], TYPOGRAPHY_LINE_HEIGHT_CLASSES[size]] : undefined,\n /** set underline thickness depending on size of Link */\n size === 'sm' ? 'decoration-1' : 'decoration-2',\n 'underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 hover:text-blue-900 active:text-blue-900 visited:text-blue-700 underline-offset-2 ',\n {\n 'font-bold': bold,\n }\n );\n\n return (\n <Component {...otherProps} className={className} data-taco=\"link\" ref={ref}>\n {children}\n </Component>\n );\n}\n\nexport const Link = React.forwardRef(LinkInner) as <T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> }\n) => React.ReactElement | null;\n"],"names":[],"mappings":";;;AAgCA,SAAS,UACL,OACA,KACF;AAEQ,QAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP,GAAG;AAAA,EAAA,IACH;AAKJ,QAAM,YAA+B,MAAM;AAE3C,QAAM,YAAY;AAAA,IACd,OAAO,CAAC,6BAA6B,IAAI,GAAG,+BAA+B,IAAI,CAAC,IAAI;AAAA;AAAA,IAEpF,SAAS,OAAO,iBAAiB;AAAA,IACjC;AAAA,IACA;AAAA,MACI,aAAa;AAAA,IAAA;AAAA,EAErB;AAGI,SAAA,sBAAA,cAAC,aAAW,GAAG,YAAY,WAAsB,aAAU,QAAO,OAC7D,QACL;AAER;AAEa,MAAA,OAAO,MAAM,WAAW,SAAS;"}
|
|
1
|
+
{"version":3,"file":"Link.js","sources":["../../../../src/components/Actions/Link/Link.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\n\nimport { TYPOGRAPHY_LINE_HEIGHT_CLASSES, TYPOGRAPHY_TEXT_SIZE_CLASSES } from '../../../utils/typography';\n\n/**\n * Link label: string text (literals, template literals, i18n helpers that return `string`, string constants),\n * or a single React element—typically a component whose output is text-only.\n * (TypeScript cannot enforce “component returns string” vs JSX; avoid non-text elements.)\n */\nexport type LinkChildren = string | React.ReactElement | null;\n\n/** Props specific to our Link component */\ntype LinkOwnProps<T extends React.ElementType = 'a'> = {\n /** Allows using a custom or framework-specific link component (e.g. Next.js or React Router) */\n as?: T;\n /** Set specific size that matches our text sizes. If it's not set, it inherits the parent size */\n size?: 'sm' | 'md' | 'lg';\n /** If true, the Link will be rendered in bold */\n bold?: boolean;\n /** The content of the Link */\n children?: LinkChildren;\n};\n\n/**\n * LinkProps combines our own props with the props of the underlying element (via `as`).\n * This allows the component to accept props like `to` for React Router or `href` for native anchors.\n * Note: `className` and `style` are explicitly excluded.\n */\nexport type LinkProps<T extends React.ElementType = 'a'> = LinkOwnProps<T> &\n Omit<React.ComponentPropsWithoutRef<T>, keyof LinkOwnProps<T> | 'className' | 'style'>;\n\nfunction LinkInner<T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> },\n ref: React.Ref<unknown>\n) {\n // Destructure and discard className/style to prevent them from being applied at runtime\n const {\n as,\n size,\n bold,\n children,\n className: _,\n style: __,\n ...otherProps\n } = props as LinkProps<T> & {\n className?: string;\n style?: React.CSSProperties;\n };\n\n const Component: React.ElementType = as || 'a';\n\n const className = cn(\n size ? [TYPOGRAPHY_TEXT_SIZE_CLASSES[size], TYPOGRAPHY_LINE_HEIGHT_CLASSES[size]] : undefined,\n /** set underline thickness depending on size of Link */\n size === 'sm' ? 'decoration-1' : 'decoration-2',\n 'underline cursor-pointer focus:outline-transparent focus-visible:yt-focus text-blue-700 focus-visible:text-blue-700 hover:text-blue-900 focus-visible:hover:text-blue-900 active:text-blue-900 focus-visible:active:text-blue-900 visited:text-blue-700 focus-visible:visited:text-blue-700 underline-offset-2 ',\n {\n 'font-bold': bold,\n }\n );\n\n return (\n <Component {...otherProps} className={className} data-taco=\"link\" ref={ref}>\n {children}\n </Component>\n );\n}\n\nexport const Link = React.forwardRef(LinkInner) as <T extends React.ElementType = 'a'>(\n props: LinkProps<T> & { ref?: React.Ref<unknown> }\n) => React.ReactElement | null;\n"],"names":[],"mappings":";;;AAgCA,SAAS,UACL,OACA,KACF;AAEQ,QAAA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,OAAO;AAAA,IACP,GAAG;AAAA,EAAA,IACH;AAKJ,QAAM,YAA+B,MAAM;AAE3C,QAAM,YAAY;AAAA,IACd,OAAO,CAAC,6BAA6B,IAAI,GAAG,+BAA+B,IAAI,CAAC,IAAI;AAAA;AAAA,IAEpF,SAAS,OAAO,iBAAiB;AAAA,IACjC;AAAA,IACA;AAAA,MACI,aAAa;AAAA,IAAA;AAAA,EAErB;AAGI,SAAA,sBAAA,cAAC,aAAW,GAAG,YAAY,WAAsB,aAAU,QAAO,OAC7D,QACL;AAER;AAEa,MAAA,OAAO,MAAM,WAAW,SAAS;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
|
-
const
|
|
4
|
+
const popover = require("@base-ui/react/popover");
|
|
5
5
|
function _interopNamespaceDefault(e) {
|
|
6
6
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
7
|
if (e) {
|
|
@@ -19,9 +19,8 @@ function _interopNamespaceDefault(e) {
|
|
|
19
19
|
return Object.freeze(n);
|
|
20
20
|
}
|
|
21
21
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
|
-
const PopoverPrimitive__namespace = /* @__PURE__ */ _interopNamespaceDefault(PopoverPrimitive);
|
|
23
22
|
const UnstyledArrow = React__namespace.forwardRef(function PopoverArrow(props, ref) {
|
|
24
|
-
return /* @__PURE__ */ React__namespace.createElement(
|
|
23
|
+
return /* @__PURE__ */ React__namespace.createElement(popover.Popover.Arrow, { className: "pointer-events-none h-[11px] w-[30px] data-[side=bottom]:top-[-10px] data-[side=left]:right-[-20px] data-[side=right]:left-[-20px] data-[side=top]:bottom-[-10px] data-[side=left]:rotate-90 data-[side=right]:-rotate-90 data-[side=top]:rotate-180" }, /* @__PURE__ */ React__namespace.createElement("svg", { ...props, ref, viewBox: "0 19 30 11" }, /* @__PURE__ */ React__namespace.createElement(
|
|
25
24
|
"path",
|
|
26
25
|
{
|
|
27
26
|
className: "fill-current text-blue-500",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Arrow.cjs","sources":["../../../src/components/Hanger/Arrow.tsx"],"sourcesContent":["import * as React from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"Arrow.cjs","sources":["../../../src/components/Hanger/Arrow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\n\nexport const UnstyledArrow = React.forwardRef<SVGSVGElement, React.SVGAttributes<SVGElement>>(function PopoverArrow(props, ref) {\n return (\n <PopoverPrimitive.Arrow className=\"pointer-events-none h-[11px] w-[30px] data-[side=bottom]:top-[-10px] data-[side=left]:right-[-20px] data-[side=right]:left-[-20px] data-[side=top]:bottom-[-10px] data-[side=left]:rotate-90 data-[side=right]:-rotate-90 data-[side=top]:rotate-180\">\n <svg {...props} ref={ref} viewBox=\"0 19 30 11\">\n <path\n className=\"fill-current text-blue-500\"\n d=\"M23.7,27.1L17,19.9C16.5,19.3,15.8,19,15,19s-1.6,0.3-2.1,0.9l-6.6,7.2C5.3,28.1,3.4,29,2,29h26 C26.7,29,24.6,28.1,23.7,27.1z\"></path>\n <path\n className=\"fill-current\"\n d=\"M23,27.8c1.1,1.2,3.4,2.2,5,2.2h2H0h2c1.7,0,3.9-1,5-2.2l6.6-7.2c0.7-0.8,2-0.8,2.7,0L23,27.8L23,27.8z\"></path>\n </svg>\n </PopoverPrimitive.Arrow>\n );\n});\n"],"names":["React","PopoverPrimitive"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGO,MAAM,gBAAgBA,iBAAM,WAA2D,SAAS,aAAa,OAAO,KAAK;AAC5H,SACKA,iCAAA,cAAAC,QAAA,QAAiB,OAAjB,EAAuB,WAAU,uPAAA,GAC7BD,iCAAA,cAAA,OAAA,EAAK,GAAG,OAAO,KAAU,SAAQ,aAC9B,GAAAA,iCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAU;AAAA,MACV,GAAE;AAAA,IAAA;AAAA,EACN,GAAAA,iCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAU;AAAA,MACV,GAAE;AAAA,IAAA;AAAA,EAAA,CACV,CACJ;AAER,CAAC;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { Popover } from "@base-ui/react/popover";
|
|
3
3
|
const UnstyledArrow = React.forwardRef(function PopoverArrow(props, ref) {
|
|
4
|
-
return /* @__PURE__ */ React.createElement(
|
|
4
|
+
return /* @__PURE__ */ React.createElement(Popover.Arrow, { className: "pointer-events-none h-[11px] w-[30px] data-[side=bottom]:top-[-10px] data-[side=left]:right-[-20px] data-[side=right]:left-[-20px] data-[side=top]:bottom-[-10px] data-[side=left]:rotate-90 data-[side=right]:-rotate-90 data-[side=top]:rotate-180" }, /* @__PURE__ */ React.createElement("svg", { ...props, ref, viewBox: "0 19 30 11" }, /* @__PURE__ */ React.createElement(
|
|
5
5
|
"path",
|
|
6
6
|
{
|
|
7
7
|
className: "fill-current text-blue-500",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Arrow.js","sources":["../../../src/components/Hanger/Arrow.tsx"],"sourcesContent":["import * as React from 'react';\nimport
|
|
1
|
+
{"version":3,"file":"Arrow.js","sources":["../../../src/components/Hanger/Arrow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\n\nexport const UnstyledArrow = React.forwardRef<SVGSVGElement, React.SVGAttributes<SVGElement>>(function PopoverArrow(props, ref) {\n return (\n <PopoverPrimitive.Arrow className=\"pointer-events-none h-[11px] w-[30px] data-[side=bottom]:top-[-10px] data-[side=left]:right-[-20px] data-[side=right]:left-[-20px] data-[side=top]:bottom-[-10px] data-[side=left]:rotate-90 data-[side=right]:-rotate-90 data-[side=top]:rotate-180\">\n <svg {...props} ref={ref} viewBox=\"0 19 30 11\">\n <path\n className=\"fill-current text-blue-500\"\n d=\"M23.7,27.1L17,19.9C16.5,19.3,15.8,19,15,19s-1.6,0.3-2.1,0.9l-6.6,7.2C5.3,28.1,3.4,29,2,29h26 C26.7,29,24.6,28.1,23.7,27.1z\"></path>\n <path\n className=\"fill-current\"\n d=\"M23,27.8c1.1,1.2,3.4,2.2,5,2.2h2H0h2c1.7,0,3.9-1,5-2.2l6.6-7.2c0.7-0.8,2-0.8,2.7,0L23,27.8L23,27.8z\"></path>\n </svg>\n </PopoverPrimitive.Arrow>\n );\n});\n"],"names":["PopoverPrimitive"],"mappings":";;AAGO,MAAM,gBAAgB,MAAM,WAA2D,SAAS,aAAa,OAAO,KAAK;AAC5H,SACK,sBAAA,cAAAA,QAAiB,OAAjB,EAAuB,WAAU,uPAAA,GAC7B,sBAAA,cAAA,OAAA,EAAK,GAAG,OAAO,KAAU,SAAQ,aAC9B,GAAA,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAU;AAAA,MACV,GAAE;AAAA,IAAA;AAAA,EACN,GAAA,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAU;AAAA,MACV,GAAE;AAAA,IAAA;AAAA,EAAA,CACV,CACJ;AAER,CAAC;"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const cn = require("clsx");
|
|
5
|
-
const
|
|
5
|
+
const popover = require("@base-ui/react/popover");
|
|
6
6
|
const IconButton = require("../LegacyComponents/IconButton/IconButton.cjs");
|
|
7
7
|
const Arrow = require("./Arrow.cjs");
|
|
8
8
|
const Localization = require("../Provider/Localization.cjs");
|
|
@@ -25,75 +25,67 @@ function _interopNamespaceDefault(e) {
|
|
|
25
25
|
return Object.freeze(n);
|
|
26
26
|
}
|
|
27
27
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
28
|
-
const PopoverPrimitive__namespace = /* @__PURE__ */ _interopNamespaceDefault(PopoverPrimitive);
|
|
29
28
|
const HangerContext = React__namespace.createContext({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
ref: null
|
|
33
|
-
});
|
|
34
|
-
const Anchor = React__namespace.forwardRef(function HangerAnchor(props, externalRef) {
|
|
35
|
-
var _a;
|
|
36
|
-
const { ref: parentRef, props: parentProps } = React__namespace.useContext(HangerContext);
|
|
37
|
-
const refCallback = mergeRefs.mergeRefs([parentRef, externalRef]);
|
|
38
|
-
let children = props.children;
|
|
39
|
-
if (React__namespace.isValidElement(props.children) && typeof ((_a = props.children) == null ? void 0 : _a.type) === "function") {
|
|
40
|
-
console.warn(
|
|
41
|
-
`Hanger.Anchor requires its child to forwardRef so that it can attach to the dom element. Did you mean to wrap '${props.children.type.name}' in React.forwardRef()? Taco has wrapped '${props.children.type.name}' in a 'span' to maintain functionality, but this may cause unintended behaviour`
|
|
42
|
-
);
|
|
43
|
-
children = /* @__PURE__ */ React__namespace.createElement("span", null, props.children);
|
|
44
|
-
}
|
|
45
|
-
return /* @__PURE__ */ React__namespace.createElement(PopoverPrimitive__namespace.Anchor, { ...parentProps, ...props, ref: refCallback, asChild: true }, children);
|
|
29
|
+
anchorRef: { current: null },
|
|
30
|
+
onClose: void 0
|
|
46
31
|
});
|
|
32
|
+
const Anchor = ({ children }) => /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, children);
|
|
47
33
|
const Title = React__namespace.forwardRef(function DialogTitle(props, ref) {
|
|
48
34
|
const className = cn("mb-1 text-base font-bold flex w-full", props.className);
|
|
49
35
|
return /* @__PURE__ */ React__namespace.createElement("span", { ...props, className, ref });
|
|
50
36
|
});
|
|
51
37
|
const Content = React__namespace.forwardRef(function HangerContent(props, ref) {
|
|
52
|
-
const { placement: side, hideWhenDetached = false, container } = props;
|
|
38
|
+
const { placement: side, hideWhenDetached = false, container, ...popoverContentProps } = props;
|
|
53
39
|
const context = React__namespace.useContext(HangerContext);
|
|
54
40
|
const { texts } = Localization.useLocalization();
|
|
55
41
|
const className = cn(
|
|
56
42
|
"wcag-blue-500 border border-transparent rounded p-3 pr-12 yt-shadow focus:border-transparent max-w-sm print:hidden",
|
|
57
43
|
props.className
|
|
58
44
|
);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
return /* @__PURE__ */ React__namespace.createElement(PopoverPrimitive__namespace.Portal, { container }, /* @__PURE__ */ React__namespace.createElement(
|
|
63
|
-
PopoverPrimitive__namespace.Content,
|
|
45
|
+
return /* @__PURE__ */ React__namespace.createElement(popover.Popover.Portal, { container }, /* @__PURE__ */ React__namespace.createElement(
|
|
46
|
+
popover.Popover.Positioner,
|
|
64
47
|
{
|
|
65
|
-
|
|
66
|
-
"data-
|
|
67
|
-
onInteractOutside: handleInteractOutside,
|
|
48
|
+
anchor: context.anchorRef,
|
|
49
|
+
className: hideWhenDetached ? "data-[anchor-hidden]:hidden" : void 0,
|
|
68
50
|
side,
|
|
69
|
-
sideOffset:
|
|
70
|
-
ref,
|
|
71
|
-
hideWhenDetached
|
|
51
|
+
sideOffset: 11
|
|
72
52
|
},
|
|
73
|
-
props.children,
|
|
74
|
-
|
|
75
|
-
/* @__PURE__ */ React__namespace.createElement(PopoverPrimitive__namespace.Close, { asChild: true }, /* @__PURE__ */ React__namespace.createElement(
|
|
76
|
-
IconButton.LegacyIconButton,
|
|
53
|
+
/* @__PURE__ */ React__namespace.createElement(popover.Popover.Popup, { ...popoverContentProps, className, "data-taco": "hanger", ref }, props.children, /* @__PURE__ */ React__namespace.createElement(Arrow.UnstyledArrow, { className: "text-blue-500" }), /* @__PURE__ */ React__namespace.createElement(
|
|
54
|
+
popover.Popover.Close,
|
|
77
55
|
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
56
|
+
render: /* @__PURE__ */ React__namespace.createElement(
|
|
57
|
+
IconButton.LegacyIconButton,
|
|
58
|
+
{
|
|
59
|
+
appearance: "primary",
|
|
60
|
+
"aria-label": texts.hanger.close,
|
|
61
|
+
className: "absolute right-0 top-0 mx-2 mt-2 text-white",
|
|
62
|
+
icon: "close",
|
|
63
|
+
onClick: context.onClose
|
|
64
|
+
}
|
|
65
|
+
)
|
|
83
66
|
}
|
|
84
67
|
))
|
|
85
68
|
));
|
|
86
69
|
});
|
|
87
70
|
const Hanger = React__namespace.forwardRef(function Hanger2(props, ref) {
|
|
88
71
|
const { anchor, children, defaultOpen = true, onClose, ...otherProps } = props;
|
|
89
|
-
const
|
|
72
|
+
const anchorRef = React__namespace.useRef(null);
|
|
73
|
+
const combinedRef = mergeRefs.mergeRefs([anchorRef, ref]);
|
|
74
|
+
const context = React__namespace.useMemo(() => ({ anchorRef, onClose }), [onClose]);
|
|
90
75
|
const [open, setOpen] = React__namespace.useState(false);
|
|
91
76
|
React__namespace.useEffect(() => {
|
|
92
77
|
if (defaultOpen) {
|
|
93
78
|
setOpen(defaultOpen);
|
|
94
79
|
}
|
|
95
80
|
}, []);
|
|
96
|
-
|
|
81
|
+
const handleOpenChange = (nextOpen, eventDetails) => {
|
|
82
|
+
if (!nextOpen && (eventDetails.reason === "outside-press" || eventDetails.reason === "focus-out")) {
|
|
83
|
+
eventDetails.cancel();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
setOpen(nextOpen);
|
|
87
|
+
};
|
|
88
|
+
return /* @__PURE__ */ React__namespace.createElement(HangerContext.Provider, { value: context }, /* @__PURE__ */ React__namespace.createElement("span", { ...otherProps, ref: combinedRef }, /* @__PURE__ */ React__namespace.createElement(popover.Popover.Root, { open, onOpenChange: handleOpenChange }, anchor, children)));
|
|
97
89
|
});
|
|
98
90
|
Hanger.Anchor = Anchor;
|
|
99
91
|
Hanger.Content = Content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hanger.cjs","sources":["../../../src/components/Hanger/Hanger.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport
|
|
1
|
+
{"version":3,"file":"Hanger.cjs","sources":["../../../src/components/Hanger/Hanger.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\n\nimport { LegacyIconButton } from '../LegacyComponents/IconButton/IconButton';\nimport { Placement } from '../..';\nimport { UnstyledArrow } from './Arrow';\nimport { useLocalization } from '../Provider/Localization';\nimport { mergeRefs } from '../../utils/mergeRefs';\nimport './Hanger.css';\n\ntype HangerContextValue = {\n /** Handler called when hanger closes by user interaction */\n onClose?: () => void;\n anchorRef: React.RefObject<HTMLElement>;\n};\nconst HangerContext = React.createContext<HangerContextValue>({\n anchorRef: { current: null },\n onClose: undefined,\n});\n\nexport type HangerTexts = {\n /** Aria-label for the close icon button of hanger */\n close: string;\n};\n\nexport type HangerAnchorProps = React.PropsWithChildren;\n// `Hanger.Anchor` is a pure pass-through that renders its child untouched. It exists only to keep\n// the composable API (<Hanger.Anchor>…</Hanger.Anchor>) — the Hanger root owns the single DOM\n// wrapper that serves as the positioning anchor, so this adds no DOM and needs no ref.\nconst Anchor: React.FC<HangerAnchorProps> = ({ children }) => <>{children}</>;\n\nexport type HangerTitleProps = React.HTMLAttributes<HTMLHeadingElement>;\nexport const Title = React.forwardRef(function DialogTitle(props: HangerTitleProps, ref: React.Ref<HTMLHeadingElement>) {\n const className = cn('mb-1 text-base font-bold flex w-full', props.className);\n return <span {...props} className={className} ref={ref} />;\n});\n\nexport type HangerContentProps = React.HTMLAttributes<HTMLDivElement> & {\n /** Set the position of the Hanger relative to its achor. Default value is `bottom` */\n placement?: Placement;\n hideWhenDetached?: boolean;\n container?: HTMLElement | null;\n};\n\nconst Content = React.forwardRef(function HangerContent(props: HangerContentProps, ref: React.Ref<HTMLDivElement>) {\n const { placement: side, hideWhenDetached = false, container, ...popoverContentProps } = props;\n const context = React.useContext(HangerContext);\n const { texts } = useLocalization();\n const className = cn(\n 'wcag-blue-500 border border-transparent rounded p-3 pr-12 yt-shadow focus:border-transparent max-w-sm print:hidden',\n props.className\n );\n\n return (\n <PopoverPrimitive.Portal container={container}>\n <PopoverPrimitive.Positioner\n anchor={context.anchorRef}\n className={hideWhenDetached ? 'data-[anchor-hidden]:hidden' : undefined}\n side={side}\n sideOffset={11}>\n <PopoverPrimitive.Popup {...popoverContentProps} className={className} data-taco=\"hanger\" ref={ref}>\n {props.children}\n <UnstyledArrow className=\"text-blue-500\" />\n <PopoverPrimitive.Close\n render={\n <LegacyIconButton\n appearance=\"primary\"\n aria-label={texts.hanger.close}\n className=\"absolute right-0 top-0 mx-2 mt-2 text-white\"\n icon=\"close\"\n onClick={context.onClose}\n />\n }\n />\n </PopoverPrimitive.Popup>\n </PopoverPrimitive.Positioner>\n </PopoverPrimitive.Portal>\n );\n});\n\nexport type HangerProps = React.PropsWithChildren<{\n /** An anchor to be used for the hanger, should not be set if `children` already contains an anchor */\n anchor?: JSX.Element;\n /**\n * Shows or hides hanger depending on the value\n * @defaultValue true\n */\n defaultOpen?: boolean;\n /** Handler called when user closes the hanger */\n onClose?: () => void;\n}>;\n\nexport type ForwardedHangerWithStatics = React.ForwardRefExoticComponent<HangerProps & React.RefAttributes<HTMLElement>> & {\n Anchor: React.FC<HangerAnchorProps>;\n Content: React.ForwardRefExoticComponent<HangerContentProps>;\n Title: React.ForwardRefExoticComponent<HangerTitleProps>;\n};\n\nexport const Hanger = React.forwardRef<HTMLSpanElement, HangerProps>(function Hanger(props, ref) {\n const { anchor, children, defaultOpen = true, onClose, ...otherProps } = props;\n const anchorRef = React.useRef<HTMLElement>(null);\n const combinedRef = mergeRefs([anchorRef as React.MutableRefObject<HTMLElement | null>, ref]);\n const context = React.useMemo(() => ({ anchorRef, onClose }), [onClose]);\n\n // we do this to ensure hangers are mounted after their containers, e.g. if the container is another portal\n const [open, setOpen] = React.useState(false);\n React.useEffect(() => {\n if (defaultOpen) {\n setOpen(defaultOpen);\n }\n }, []);\n\n // Hanger should only close from its close button, matching the previous Radix onInteractOutside behavior.\n const handleOpenChange = (nextOpen: boolean, eventDetails: PopoverPrimitive.Root.ChangeEventDetails) => {\n if (!nextOpen && (eventDetails.reason === 'outside-press' || eventDetails.reason === 'focus-out')) {\n eventDetails.cancel();\n return;\n }\n\n setOpen(nextOpen);\n };\n\n // Single inline <span> wrapper: serves as the Floating UI anchor (its rect matches the\n // in-flow trigger child) and contains the FloatingFocusManager guard spans Base UI injects\n // when open, so they aren't siblings of the Hanger in parent IntersectionObservers\n // (e.g. OverflowGroup's) and don't get counted as overflowed children.\n return (\n <HangerContext.Provider value={context}>\n <span {...otherProps} ref={combinedRef as React.Ref<HTMLSpanElement>}>\n <PopoverPrimitive.Root open={open} onOpenChange={handleOpenChange}>\n {/* Anchor via the `anchor` prop. */}\n {anchor}\n {/* Composition (<Hanger.Anchor>) and the popup Content (portaled out) come through {children}. */}\n {children}\n </PopoverPrimitive.Root>\n </span>\n </HangerContext.Provider>\n );\n}) as ForwardedHangerWithStatics;\nHanger.Anchor = Anchor;\nHanger.Content = Content;\nHanger.Title = Title;\n"],"names":["React","useLocalization","PopoverPrimitive","UnstyledArrow","LegacyIconButton","Hanger","mergeRefs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,gBAAgBA,iBAAM,cAAkC;AAAA,EAC1D,WAAW,EAAE,SAAS,KAAK;AAAA,EAC3B,SAAS;AACb,CAAC;AAWD,MAAM,SAAsC,CAAC,EAAE,SAAS,sFAAS,QAAS;AAGnE,MAAM,QAAQA,iBAAM,WAAW,SAAS,YAAY,OAAyB,KAAoC;AACpH,QAAM,YAAY,GAAG,wCAAwC,MAAM,SAAS;AAC5E,SAAQA,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O,EAAE,WAAW,QAAQ,IAAI,CAAC,OAAO,CAAC;AAGvE,QAAM,CAAC,MAAM,OAAO,IAAIA,iBAAM,SAAS,KAAK;AAC5CA,mBAAM,UAAU,MAAM;AAClB,QAAI,aAAa;AACb,cAAQ,WAAW;AAAA,IAAA;AAAA,EAE3B,GAAG,EAAE;AAGC,QAAA,mBAAmB,CAAC,UAAmB,iBAA2D;AACpG,QAAI,CAAC,aAAa,aAAa,WAAW,mBAAmB,aAAa,WAAW,cAAc;AAC/F,mBAAa,OAAO;AACpB;AAAA,IAAA;AAGJ,YAAQ,QAAQ;AAAA,EACpB;AAOI,SAAAA,iCAAA,cAAC,cAAc,UAAd,EAAuB,OAAO,QAC3B,GAAAA,iCAAA,cAAC,QAAM,EAAA,GAAG,YAAY,KAAK,eACtBA,iCAAA,cAAAE,QAAAA,QAAiB,MAAjB,EAAsB,MAAY,cAAc,iBAE5C,GAAA,QAEA,QACL,CACJ,CACJ;AAER,CAAC;AACD,OAAO,SAAS;AAChB,OAAO,UAAU;AACjB,OAAO,QAAQ;;;"}
|
|
@@ -4,7 +4,7 @@ export type HangerTexts = {
|
|
|
4
4
|
/** Aria-label for the close icon button of hanger */
|
|
5
5
|
close: string;
|
|
6
6
|
};
|
|
7
|
-
export type HangerAnchorProps = React.
|
|
7
|
+
export type HangerAnchorProps = React.PropsWithChildren;
|
|
8
8
|
export type HangerTitleProps = React.HTMLAttributes<HTMLHeadingElement>;
|
|
9
9
|
export declare const Title: React.ForwardRefExoticComponent<HangerTitleProps & React.RefAttributes<HTMLHeadingElement>>;
|
|
10
10
|
export type HangerContentProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
@@ -25,7 +25,7 @@ export type HangerProps = React.PropsWithChildren<{
|
|
|
25
25
|
onClose?: () => void;
|
|
26
26
|
}>;
|
|
27
27
|
export type ForwardedHangerWithStatics = React.ForwardRefExoticComponent<HangerProps & React.RefAttributes<HTMLElement>> & {
|
|
28
|
-
Anchor: React.
|
|
28
|
+
Anchor: React.FC<HangerAnchorProps>;
|
|
29
29
|
Content: React.ForwardRefExoticComponent<HangerContentProps>;
|
|
30
30
|
Title: React.ForwardRefExoticComponent<HangerTitleProps>;
|
|
31
31
|
};
|
|
@@ -1,79 +1,72 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import cn from "clsx";
|
|
3
|
-
import
|
|
3
|
+
import { Popover } from "@base-ui/react/popover";
|
|
4
4
|
import { LegacyIconButton } from "../LegacyComponents/IconButton/IconButton.js";
|
|
5
5
|
import { UnstyledArrow } from "./Arrow.js";
|
|
6
6
|
import { useLocalization } from "../Provider/Localization.js";
|
|
7
7
|
import { mergeRefs } from "../../utils/mergeRefs.js";
|
|
8
8
|
/* empty css */
|
|
9
9
|
const HangerContext = React.createContext({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ref: null
|
|
13
|
-
});
|
|
14
|
-
const Anchor = React.forwardRef(function HangerAnchor(props, externalRef) {
|
|
15
|
-
var _a;
|
|
16
|
-
const { ref: parentRef, props: parentProps } = React.useContext(HangerContext);
|
|
17
|
-
const refCallback = mergeRefs([parentRef, externalRef]);
|
|
18
|
-
let children = props.children;
|
|
19
|
-
if (React.isValidElement(props.children) && typeof ((_a = props.children) == null ? void 0 : _a.type) === "function") {
|
|
20
|
-
console.warn(
|
|
21
|
-
`Hanger.Anchor requires its child to forwardRef so that it can attach to the dom element. Did you mean to wrap '${props.children.type.name}' in React.forwardRef()? Taco has wrapped '${props.children.type.name}' in a 'span' to maintain functionality, but this may cause unintended behaviour`
|
|
22
|
-
);
|
|
23
|
-
children = /* @__PURE__ */ React.createElement("span", null, props.children);
|
|
24
|
-
}
|
|
25
|
-
return /* @__PURE__ */ React.createElement(PopoverPrimitive.Anchor, { ...parentProps, ...props, ref: refCallback, asChild: true }, children);
|
|
10
|
+
anchorRef: { current: null },
|
|
11
|
+
onClose: void 0
|
|
26
12
|
});
|
|
13
|
+
const Anchor = ({ children }) => /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
27
14
|
const Title = React.forwardRef(function DialogTitle(props, ref) {
|
|
28
15
|
const className = cn("mb-1 text-base font-bold flex w-full", props.className);
|
|
29
16
|
return /* @__PURE__ */ React.createElement("span", { ...props, className, ref });
|
|
30
17
|
});
|
|
31
18
|
const Content = React.forwardRef(function HangerContent(props, ref) {
|
|
32
|
-
const { placement: side, hideWhenDetached = false, container } = props;
|
|
19
|
+
const { placement: side, hideWhenDetached = false, container, ...popoverContentProps } = props;
|
|
33
20
|
const context = React.useContext(HangerContext);
|
|
34
21
|
const { texts } = useLocalization();
|
|
35
22
|
const className = cn(
|
|
36
23
|
"wcag-blue-500 border border-transparent rounded p-3 pr-12 yt-shadow focus:border-transparent max-w-sm print:hidden",
|
|
37
24
|
props.className
|
|
38
25
|
);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
return /* @__PURE__ */ React.createElement(PopoverPrimitive.Portal, { container }, /* @__PURE__ */ React.createElement(
|
|
43
|
-
PopoverPrimitive.Content,
|
|
26
|
+
return /* @__PURE__ */ React.createElement(Popover.Portal, { container }, /* @__PURE__ */ React.createElement(
|
|
27
|
+
Popover.Positioner,
|
|
44
28
|
{
|
|
45
|
-
|
|
46
|
-
"data-
|
|
47
|
-
onInteractOutside: handleInteractOutside,
|
|
29
|
+
anchor: context.anchorRef,
|
|
30
|
+
className: hideWhenDetached ? "data-[anchor-hidden]:hidden" : void 0,
|
|
48
31
|
side,
|
|
49
|
-
sideOffset:
|
|
50
|
-
ref,
|
|
51
|
-
hideWhenDetached
|
|
32
|
+
sideOffset: 11
|
|
52
33
|
},
|
|
53
|
-
props.children,
|
|
54
|
-
|
|
55
|
-
/* @__PURE__ */ React.createElement(PopoverPrimitive.Close, { asChild: true }, /* @__PURE__ */ React.createElement(
|
|
56
|
-
LegacyIconButton,
|
|
34
|
+
/* @__PURE__ */ React.createElement(Popover.Popup, { ...popoverContentProps, className, "data-taco": "hanger", ref }, props.children, /* @__PURE__ */ React.createElement(UnstyledArrow, { className: "text-blue-500" }), /* @__PURE__ */ React.createElement(
|
|
35
|
+
Popover.Close,
|
|
57
36
|
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
37
|
+
render: /* @__PURE__ */ React.createElement(
|
|
38
|
+
LegacyIconButton,
|
|
39
|
+
{
|
|
40
|
+
appearance: "primary",
|
|
41
|
+
"aria-label": texts.hanger.close,
|
|
42
|
+
className: "absolute right-0 top-0 mx-2 mt-2 text-white",
|
|
43
|
+
icon: "close",
|
|
44
|
+
onClick: context.onClose
|
|
45
|
+
}
|
|
46
|
+
)
|
|
63
47
|
}
|
|
64
48
|
))
|
|
65
49
|
));
|
|
66
50
|
});
|
|
67
51
|
const Hanger = React.forwardRef(function Hanger2(props, ref) {
|
|
68
52
|
const { anchor, children, defaultOpen = true, onClose, ...otherProps } = props;
|
|
69
|
-
const
|
|
53
|
+
const anchorRef = React.useRef(null);
|
|
54
|
+
const combinedRef = mergeRefs([anchorRef, ref]);
|
|
55
|
+
const context = React.useMemo(() => ({ anchorRef, onClose }), [onClose]);
|
|
70
56
|
const [open, setOpen] = React.useState(false);
|
|
71
57
|
React.useEffect(() => {
|
|
72
58
|
if (defaultOpen) {
|
|
73
59
|
setOpen(defaultOpen);
|
|
74
60
|
}
|
|
75
61
|
}, []);
|
|
76
|
-
|
|
62
|
+
const handleOpenChange = (nextOpen, eventDetails) => {
|
|
63
|
+
if (!nextOpen && (eventDetails.reason === "outside-press" || eventDetails.reason === "focus-out")) {
|
|
64
|
+
eventDetails.cancel();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
setOpen(nextOpen);
|
|
68
|
+
};
|
|
69
|
+
return /* @__PURE__ */ React.createElement(HangerContext.Provider, { value: context }, /* @__PURE__ */ React.createElement("span", { ...otherProps, ref: combinedRef }, /* @__PURE__ */ React.createElement(Popover.Root, { open, onOpenChange: handleOpenChange }, anchor, children)));
|
|
77
70
|
});
|
|
78
71
|
Hanger.Anchor = Anchor;
|
|
79
72
|
Hanger.Content = Content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hanger.js","sources":["../../../src/components/Hanger/Hanger.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport
|
|
1
|
+
{"version":3,"file":"Hanger.js","sources":["../../../src/components/Hanger/Hanger.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\n\nimport { LegacyIconButton } from '../LegacyComponents/IconButton/IconButton';\nimport { Placement } from '../..';\nimport { UnstyledArrow } from './Arrow';\nimport { useLocalization } from '../Provider/Localization';\nimport { mergeRefs } from '../../utils/mergeRefs';\nimport './Hanger.css';\n\ntype HangerContextValue = {\n /** Handler called when hanger closes by user interaction */\n onClose?: () => void;\n anchorRef: React.RefObject<HTMLElement>;\n};\nconst HangerContext = React.createContext<HangerContextValue>({\n anchorRef: { current: null },\n onClose: undefined,\n});\n\nexport type HangerTexts = {\n /** Aria-label for the close icon button of hanger */\n close: string;\n};\n\nexport type HangerAnchorProps = React.PropsWithChildren;\n// `Hanger.Anchor` is a pure pass-through that renders its child untouched. It exists only to keep\n// the composable API (<Hanger.Anchor>…</Hanger.Anchor>) — the Hanger root owns the single DOM\n// wrapper that serves as the positioning anchor, so this adds no DOM and needs no ref.\nconst Anchor: React.FC<HangerAnchorProps> = ({ children }) => <>{children}</>;\n\nexport type HangerTitleProps = React.HTMLAttributes<HTMLHeadingElement>;\nexport const Title = React.forwardRef(function DialogTitle(props: HangerTitleProps, ref: React.Ref<HTMLHeadingElement>) {\n const className = cn('mb-1 text-base font-bold flex w-full', props.className);\n return <span {...props} className={className} ref={ref} />;\n});\n\nexport type HangerContentProps = React.HTMLAttributes<HTMLDivElement> & {\n /** Set the position of the Hanger relative to its achor. Default value is `bottom` */\n placement?: Placement;\n hideWhenDetached?: boolean;\n container?: HTMLElement | null;\n};\n\nconst Content = React.forwardRef(function HangerContent(props: HangerContentProps, ref: React.Ref<HTMLDivElement>) {\n const { placement: side, hideWhenDetached = false, container, ...popoverContentProps } = props;\n const context = React.useContext(HangerContext);\n const { texts } = useLocalization();\n const className = cn(\n 'wcag-blue-500 border border-transparent rounded p-3 pr-12 yt-shadow focus:border-transparent max-w-sm print:hidden',\n props.className\n );\n\n return (\n <PopoverPrimitive.Portal container={container}>\n <PopoverPrimitive.Positioner\n anchor={context.anchorRef}\n className={hideWhenDetached ? 'data-[anchor-hidden]:hidden' : undefined}\n side={side}\n sideOffset={11}>\n <PopoverPrimitive.Popup {...popoverContentProps} className={className} data-taco=\"hanger\" ref={ref}>\n {props.children}\n <UnstyledArrow className=\"text-blue-500\" />\n <PopoverPrimitive.Close\n render={\n <LegacyIconButton\n appearance=\"primary\"\n aria-label={texts.hanger.close}\n className=\"absolute right-0 top-0 mx-2 mt-2 text-white\"\n icon=\"close\"\n onClick={context.onClose}\n />\n }\n />\n </PopoverPrimitive.Popup>\n </PopoverPrimitive.Positioner>\n </PopoverPrimitive.Portal>\n );\n});\n\nexport type HangerProps = React.PropsWithChildren<{\n /** An anchor to be used for the hanger, should not be set if `children` already contains an anchor */\n anchor?: JSX.Element;\n /**\n * Shows or hides hanger depending on the value\n * @defaultValue true\n */\n defaultOpen?: boolean;\n /** Handler called when user closes the hanger */\n onClose?: () => void;\n}>;\n\nexport type ForwardedHangerWithStatics = React.ForwardRefExoticComponent<HangerProps & React.RefAttributes<HTMLElement>> & {\n Anchor: React.FC<HangerAnchorProps>;\n Content: React.ForwardRefExoticComponent<HangerContentProps>;\n Title: React.ForwardRefExoticComponent<HangerTitleProps>;\n};\n\nexport const Hanger = React.forwardRef<HTMLSpanElement, HangerProps>(function Hanger(props, ref) {\n const { anchor, children, defaultOpen = true, onClose, ...otherProps } = props;\n const anchorRef = React.useRef<HTMLElement>(null);\n const combinedRef = mergeRefs([anchorRef as React.MutableRefObject<HTMLElement | null>, ref]);\n const context = React.useMemo(() => ({ anchorRef, onClose }), [onClose]);\n\n // we do this to ensure hangers are mounted after their containers, e.g. if the container is another portal\n const [open, setOpen] = React.useState(false);\n React.useEffect(() => {\n if (defaultOpen) {\n setOpen(defaultOpen);\n }\n }, []);\n\n // Hanger should only close from its close button, matching the previous Radix onInteractOutside behavior.\n const handleOpenChange = (nextOpen: boolean, eventDetails: PopoverPrimitive.Root.ChangeEventDetails) => {\n if (!nextOpen && (eventDetails.reason === 'outside-press' || eventDetails.reason === 'focus-out')) {\n eventDetails.cancel();\n return;\n }\n\n setOpen(nextOpen);\n };\n\n // Single inline <span> wrapper: serves as the Floating UI anchor (its rect matches the\n // in-flow trigger child) and contains the FloatingFocusManager guard spans Base UI injects\n // when open, so they aren't siblings of the Hanger in parent IntersectionObservers\n // (e.g. OverflowGroup's) and don't get counted as overflowed children.\n return (\n <HangerContext.Provider value={context}>\n <span {...otherProps} ref={combinedRef as React.Ref<HTMLSpanElement>}>\n <PopoverPrimitive.Root open={open} onOpenChange={handleOpenChange}>\n {/* Anchor via the `anchor` prop. */}\n {anchor}\n {/* Composition (<Hanger.Anchor>) and the popup Content (portaled out) come through {children}. */}\n {children}\n </PopoverPrimitive.Root>\n </span>\n </HangerContext.Provider>\n );\n}) as ForwardedHangerWithStatics;\nHanger.Anchor = Anchor;\nHanger.Content = Content;\nHanger.Title = Title;\n"],"names":["PopoverPrimitive","Hanger"],"mappings":";;;;;;;;AAgBA,MAAM,gBAAgB,MAAM,cAAkC;AAAA,EAC1D,WAAW,EAAE,SAAS,KAAK;AAAA,EAC3B,SAAS;AACb,CAAC;AAWD,MAAM,SAAsC,CAAC,EAAE,SAAS,gEAAS,QAAS;AAGnE,MAAM,QAAQ,MAAM,WAAW,SAAS,YAAY,OAAyB,KAAoC;AACpH,QAAM,YAAY,GAAG,wCAAwC,MAAM,SAAS;AAC5E,SAAQ,sBAAA,cAAA,QAAA,EAAM,GAAG,OAAO,WAAsB,KAAU;AAC5D,CAAC;AASD,MAAM,UAAU,MAAM,WAAW,SAAS,cAA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,IAAA;AAAA,EAE3B,GAAG,EAAE;AAGC,QAAA,mBAAmB,CAAC,UAAmB,iBAA2D;AACpG,QAAI,CAAC,aAAa,aAAa,WAAW,mBAAmB,aAAa,WAAW,cAAc;AAC/F,mBAAa,OAAO;AACpB;AAAA,IAAA;AAGJ,YAAQ,QAAQ;AAAA,EACpB;AAOI,SAAA,sBAAA,cAAC,cAAc,UAAd,EAAuB,OAAO,QAC3B,GAAA,sBAAA,cAAC,QAAM,EAAA,GAAG,YAAY,KAAK,eACtB,sBAAA,cAAAD,QAAiB,MAAjB,EAAsB,MAAY,cAAc,iBAE5C,GAAA,QAEA,QACL,CACJ,CACJ;AAER,CAAC;AACD,OAAO,SAAS;AAChB,OAAO,UAAU;AACjB,OAAO,QAAQ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelect.cjs","sources":["../../../src/components/Select/useSelect.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { nanoid } from 'nanoid';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { useLocalization } from '../Provider/Localization';\nimport { SelectProps } from './Select';\nimport { ListboxProps } from '../Listbox/Listbox';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { setInputValueByRef, findByValue, useFlattenedData, sanitizeItem } from '../Listbox/util';\nimport { ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { createCustomEvent } from '../../utils/input';\n\ntype InternalButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\ntype InternalListboxProps = ListboxProps & { ref: React.ForwardedRef<HTMLInputElement> };\ntype InternalInputProps = React.InputHTMLAttributes<HTMLInputElement> & { ref: React.ForwardedRef<HTMLInputElement> };\n\ntype useSelect = React.HtmlHTMLAttributes<HTMLDivElement> & {\n button: InternalButtonProps;\n listbox: InternalListboxProps;\n input: InternalInputProps;\n popover: Pick<PopoverPrimitive.PopoverProps, 'onOpenChange' | 'open'>;\n text: string | JSX.Element;\n more?: number;\n};\n\nexport const useSelect = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n multiselect,\n onBlur,\n onClick: _1,\n onChange,\n readOnly,\n tabIndex,\n value,\n ...otherProps\n }: SelectProps,\n ref: React.Ref<HTMLInputElement>\n): useSelect => {\n const { texts } = useLocalization();\n const flattenedData = useFlattenedData(data);\n const listboxInputRef = useMergedRef<HTMLInputElement>(ref);\n const [open, setOpen] = React.useState(false);\n const id = React.useMemo(() => nativeId || `select_${nanoid()}`, [nativeId]);\n const inputRef = React.useRef<HTMLInputElement>(null);\n const buttonId = `${id}-button`;\n // support 'escape' resetting to the value that was set when the listbox opened\n const [lastValue, setLastValue] = React.useState<ScrollableListItemValue | undefined>(value);\n\n React.useEffect(() => {\n setLastValue(value);\n }, [open]);\n\n React.useEffect(() => {\n if (value === undefined) {\n if (defaultValue !== undefined && findByValue(flattenedData, defaultValue)) {\n setInputValueByRef(inputRef.current, defaultValue);\n } else if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n } else if (!multiselect && !findByValue(flattenedData, value)) {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n }\n }, []);\n\n // event handlers\n const handleButtonKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n switch (event.key) {\n case 'Escape': {\n event.preventDefault();\n if (lastValue !== undefined) {\n setInputValueByRef(listboxInputRef.current, lastValue);\n }\n\n setOpen(false);\n break;\n }\n\n case 'Tab':\n case 'Enter': {\n if (event.key !== 'Tab') {\n event.preventDefault();\n }\n setOpen(false);\n break;\n }\n\n default:\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>): void => {\n event.preventDefault();\n if (!multiselect) {\n setOpen(false);\n if (onBlur) {\n onBlur(createCustomEvent('blur') as unknown as React.FocusEvent<HTMLElement, Element>);\n }\n }\n };\n\n let text: string | JSX.Element = '';\n let more = 0;\n\n if (value !== undefined) {\n if (multiselect) {\n const selectedValues = value?.toString().split(',') || [];\n\n if (selectedValues.length === flattenedData.filter(item => !item.disabled).length) {\n text = texts.select.allOptionsSelected;\n } else {\n text = findByValue(flattenedData, selectedValues[0])?.text ?? '';\n more = selectedValues.length > 1 ? selectedValues.length - 1 : 0;\n }\n } else {\n const item = findByValue(flattenedData, value);\n\n if (item) {\n text = item.icon ? (\n <>\n {React.cloneElement(item.icon, {\n className: cn(item.icon.props.className, 'mr-1 -mt-px'),\n })}\n {item.text}\n </>\n ) : (\n item.text\n );\n }\n }\n }\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(flattenedData.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const handleButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (readOnly) {\n event.preventDefault();\n }\n };\n\n // select the value text if the select is readonly\n const handleButtonFocus = (event: React.FocusEvent<HTMLButtonElement>) => {\n if (readOnly) {\n const value = event.currentTarget.querySelector(':first-child');\n\n if (value) {\n window.getSelection()?.selectAllChildren?.(value);\n }\n }\n };\n\n const button: InternalButtonProps = {\n 'aria-haspopup': 'listbox' as const,\n 'aria-label': ariaLabel ? `${ariaLabel} ${text}` : undefined,\n 'aria-labelledby': ariaLabelledBy ? `${ariaLabelledBy} ${buttonId}` : undefined,\n 'aria-readonly': readOnly ? 'true' : undefined,\n disabled: disabled,\n id: buttonId,\n onClick: handleButtonClick,\n onFocus: handleButtonFocus,\n onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,\n tabIndex,\n type: 'button',\n };\n\n const listbox: InternalListboxProps = {\n ...otherProps,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n emptyValue,\n onBlur,\n onClick: handleListboxClick,\n onChange: event => {\n setInputValueByRef(inputRef.current, event.target.value);\n },\n onKeyDown: handleListboxKeyDown,\n ref: listboxInputRef,\n value,\n };\n\n const input: InternalInputProps = {\n onChange: handleInputChange,\n ref: inputRef,\n value: String(value ?? ''),\n };\n\n return {\n button,\n listbox,\n input,\n popover: {\n open,\n onOpenChange: setOpen,\n },\n text,\n more,\n };\n};\n"],"names":["useLocalization","useFlattenedData","useMergedRef","React","nanoid","findByValue","setInputValueByRef","_a","createCustomEvent","sanitizeItem","i","value","input"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAM,YAAY,CACrB;AAAA,EACI,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,OAAO,CAAC;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,IAAI;AAAA,EACJ;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACP,GACA,QACY;;AACN,QAAA,EAAE,MAAM,IAAIA,6BAAgB;AAC5B,QAAA,gBAAgBC,sBAAiB,IAAI;AACrC,QAAA,kBAAkBC,0BAA+B,GAAG;AAC1D,QAAM,CAAC,MAAM,OAAO,IAAIC,iBAAM,SAAS,KAAK;AACtC,QAAA,KAAKA,iBAAM,QAAQ,MAAM,YAAY,UAAUC,c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;AACfL,WAAAA,mBAAmB,SAAS,SAAS,MAAM,OAAO,KAAK;AAAA,IAC3D;AAAA,IACA,WAAW;AAAA,IACX,KAAK;AAAA,IACL;AAAA,EACJ;AAEA,QAAMM,UAA4B;AAAA,IAC9B,UAAU;AAAA,IACV,KAAK;AAAA,IACL,OAAO,OAAO,SAAS,EAAE;AAAA,EAC7B;AAEO,SAAA;AAAA,IACH;AAAA,IACA;AAAA,IAAA,OACAA;AAAAA,IACA,SAAS;AAAA,MACL;AAAA,MACA,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"useSelect.cjs","sources":["../../../src/components/Select/useSelect.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { nanoid } from 'nanoid';\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\nimport { useLocalization } from '../Provider/Localization';\nimport { SelectProps } from './Select';\nimport { ListboxProps } from '../Listbox/Listbox';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { setInputValueByRef, findByValue, useFlattenedData, sanitizeItem } from '../Listbox/util';\nimport { ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { createCustomEvent } from '../../utils/input';\n\ntype InternalButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\ntype InternalListboxProps = ListboxProps & { ref: React.ForwardedRef<HTMLInputElement> };\ntype InternalInputProps = React.InputHTMLAttributes<HTMLInputElement> & { ref: React.ForwardedRef<HTMLInputElement> };\n\ntype useSelect = React.HtmlHTMLAttributes<HTMLDivElement> & {\n button: InternalButtonProps;\n listbox: InternalListboxProps;\n input: InternalInputProps;\n popover: Pick<PopoverPrimitive.Root.Props, 'onOpenChange' | 'open'>;\n text: string | JSX.Element;\n more?: number;\n};\n\nexport const useSelect = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n multiselect,\n onBlur,\n onClick: _1,\n onChange,\n readOnly,\n tabIndex,\n value,\n ...otherProps\n }: SelectProps,\n ref: React.Ref<HTMLInputElement>\n): useSelect => {\n const { texts } = useLocalization();\n const flattenedData = useFlattenedData(data);\n const listboxInputRef = useMergedRef<HTMLInputElement>(ref);\n const [open, setOpen] = React.useState(false);\n const id = React.useMemo(() => nativeId || `select_${nanoid()}`, [nativeId]);\n const inputRef = React.useRef<HTMLInputElement>(null);\n const buttonId = `${id}-button`;\n // support 'escape' resetting to the value that was set when the listbox opened\n const [lastValue, setLastValue] = React.useState<ScrollableListItemValue | undefined>(value);\n\n React.useEffect(() => {\n setLastValue(value);\n }, [open]);\n\n React.useEffect(() => {\n if (value === undefined) {\n if (defaultValue !== undefined && findByValue(flattenedData, defaultValue)) {\n setInputValueByRef(inputRef.current, defaultValue);\n } else if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n } else if (!multiselect && !findByValue(flattenedData, value)) {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n }\n }, []);\n\n // event handlers\n const handleButtonKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n switch (event.key) {\n case 'Escape': {\n event.preventDefault();\n if (lastValue !== undefined) {\n setInputValueByRef(listboxInputRef.current, lastValue);\n }\n\n setOpen(false);\n break;\n }\n\n case 'Tab':\n case 'Enter': {\n if (event.key !== 'Tab') {\n event.preventDefault();\n }\n setOpen(false);\n break;\n }\n\n default:\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>): void => {\n event.preventDefault();\n if (!multiselect) {\n setOpen(false);\n if (onBlur) {\n onBlur(createCustomEvent('blur') as unknown as React.FocusEvent<HTMLElement, Element>);\n }\n }\n };\n\n let text: string | JSX.Element = '';\n let more = 0;\n\n if (value !== undefined) {\n if (multiselect) {\n const selectedValues = value?.toString().split(',') || [];\n\n if (selectedValues.length === flattenedData.filter(item => !item.disabled).length) {\n text = texts.select.allOptionsSelected;\n } else {\n text = findByValue(flattenedData, selectedValues[0])?.text ?? '';\n more = selectedValues.length > 1 ? selectedValues.length - 1 : 0;\n }\n } else {\n const item = findByValue(flattenedData, value);\n\n if (item) {\n text = item.icon ? (\n <>\n {React.cloneElement(item.icon, {\n className: cn(item.icon.props.className, 'mr-1 -mt-px'),\n })}\n {item.text}\n </>\n ) : (\n item.text\n );\n }\n }\n }\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(flattenedData.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const handleButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (readOnly) {\n event.preventDefault();\n }\n };\n\n // select the value text if the select is readonly\n const handleButtonFocus = (event: React.FocusEvent<HTMLButtonElement>) => {\n if (readOnly) {\n const value = event.currentTarget.querySelector(':first-child');\n\n if (value) {\n window.getSelection()?.selectAllChildren?.(value);\n }\n }\n };\n\n const button: InternalButtonProps = {\n 'aria-haspopup': 'listbox' as const,\n 'aria-label': ariaLabel ? `${ariaLabel} ${text}` : undefined,\n 'aria-labelledby': ariaLabelledBy ? `${ariaLabelledBy} ${buttonId}` : undefined,\n 'aria-readonly': readOnly ? 'true' : undefined,\n disabled: disabled,\n id: buttonId,\n onClick: handleButtonClick,\n onFocus: handleButtonFocus,\n onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,\n tabIndex,\n type: 'button',\n };\n\n const listbox: InternalListboxProps = {\n ...otherProps,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n emptyValue,\n onBlur,\n onClick: handleListboxClick,\n onChange: event => {\n setInputValueByRef(inputRef.current, event.target.value);\n },\n onKeyDown: handleListboxKeyDown,\n ref: listboxInputRef,\n value,\n };\n\n const input: InternalInputProps = {\n onChange: handleInputChange,\n ref: inputRef,\n value: String(value ?? ''),\n };\n\n return {\n button,\n listbox,\n input,\n popover: {\n open,\n onOpenChange: setOpen,\n },\n text,\n more,\n };\n};\n"],"names":["useLocalization","useFlattenedData","useMergedRef","React","nanoid","findByValue","setInputValueByRef","_a","createCustomEvent","sanitizeItem","i","value","input"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAM,YAAY,CACrB;AAAA,EACI,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,OAAO,CAAC;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,IAAI;AAAA,EACJ;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACP,GACA,QACY;;AACN,QAAA,EAAE,MAAM,IAAIA,6BAAgB;AAC5B,QAAA,gBAAgBC,sBAAiB,IAAI;AACrC,QAAA,kBAAkBC,0BAA+B,GAAG;AAC1D,QAAM,CAAC,MAAM,OAAO,IAAIC,iBAAM,SAAS,KAAK;AACtC,QAAA,KAAKA,iBAAM,QAAQ,MAAM,YAAY,UAAUC,cAAQ,CAAA,IAAI,CAAC,QAAQ,CAAC;AACrE,QAAA,WAAWD,iBAAM,OAAyB,IAAI;AAC9C,QAAA,WAAW,GAAG,EAAE;AAEtB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A,EACJ;AAEA,QAAMM,UAA4B;AAAA,IAC9B,UAAU;AAAA,IACV,KAAK;AAAA,IACL,OAAO,OAAO,SAAS,EAAE;AAAA,EAC7B;AAEO,SAAA;AAAA,IACH;AAAA,IACA;AAAA,IAAA,OACAA;AAAAA,IACA,SAAS;AAAA,MACL;AAAA,MACA,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Popover as PopoverPrimitive } from '@base-ui/react/popover';
|
|
1
2
|
import { SelectProps } from './Select';
|
|
2
3
|
import { ListboxProps } from '../Listbox/Listbox';
|
|
3
4
|
import * as React from 'react';
|
|
4
|
-
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
5
5
|
type InternalButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
6
6
|
type InternalListboxProps = ListboxProps & {
|
|
7
7
|
ref: React.ForwardedRef<HTMLInputElement>;
|
|
@@ -13,7 +13,7 @@ type useSelect = React.HtmlHTMLAttributes<HTMLDivElement> & {
|
|
|
13
13
|
button: InternalButtonProps;
|
|
14
14
|
listbox: InternalListboxProps;
|
|
15
15
|
input: InternalInputProps;
|
|
16
|
-
popover: Pick<PopoverPrimitive.
|
|
16
|
+
popover: Pick<PopoverPrimitive.Root.Props, 'onOpenChange' | 'open'>;
|
|
17
17
|
text: string | JSX.Element;
|
|
18
18
|
more?: number;
|
|
19
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelect.js","sources":["../../../src/components/Select/useSelect.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { nanoid } from 'nanoid';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { useLocalization } from '../Provider/Localization';\nimport { SelectProps } from './Select';\nimport { ListboxProps } from '../Listbox/Listbox';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { setInputValueByRef, findByValue, useFlattenedData, sanitizeItem } from '../Listbox/util';\nimport { ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { createCustomEvent } from '../../utils/input';\n\ntype InternalButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\ntype InternalListboxProps = ListboxProps & { ref: React.ForwardedRef<HTMLInputElement> };\ntype InternalInputProps = React.InputHTMLAttributes<HTMLInputElement> & { ref: React.ForwardedRef<HTMLInputElement> };\n\ntype useSelect = React.HtmlHTMLAttributes<HTMLDivElement> & {\n button: InternalButtonProps;\n listbox: InternalListboxProps;\n input: InternalInputProps;\n popover: Pick<PopoverPrimitive.PopoverProps, 'onOpenChange' | 'open'>;\n text: string | JSX.Element;\n more?: number;\n};\n\nexport const useSelect = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n multiselect,\n onBlur,\n onClick: _1,\n onChange,\n readOnly,\n tabIndex,\n value,\n ...otherProps\n }: SelectProps,\n ref: React.Ref<HTMLInputElement>\n): useSelect => {\n const { texts } = useLocalization();\n const flattenedData = useFlattenedData(data);\n const listboxInputRef = useMergedRef<HTMLInputElement>(ref);\n const [open, setOpen] = React.useState(false);\n const id = React.useMemo(() => nativeId || `select_${nanoid()}`, [nativeId]);\n const inputRef = React.useRef<HTMLInputElement>(null);\n const buttonId = `${id}-button`;\n // support 'escape' resetting to the value that was set when the listbox opened\n const [lastValue, setLastValue] = React.useState<ScrollableListItemValue | undefined>(value);\n\n React.useEffect(() => {\n setLastValue(value);\n }, [open]);\n\n React.useEffect(() => {\n if (value === undefined) {\n if (defaultValue !== undefined && findByValue(flattenedData, defaultValue)) {\n setInputValueByRef(inputRef.current, defaultValue);\n } else if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n } else if (!multiselect && !findByValue(flattenedData, value)) {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n }\n }, []);\n\n // event handlers\n const handleButtonKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n switch (event.key) {\n case 'Escape': {\n event.preventDefault();\n if (lastValue !== undefined) {\n setInputValueByRef(listboxInputRef.current, lastValue);\n }\n\n setOpen(false);\n break;\n }\n\n case 'Tab':\n case 'Enter': {\n if (event.key !== 'Tab') {\n event.preventDefault();\n }\n setOpen(false);\n break;\n }\n\n default:\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>): void => {\n event.preventDefault();\n if (!multiselect) {\n setOpen(false);\n if (onBlur) {\n onBlur(createCustomEvent('blur') as unknown as React.FocusEvent<HTMLElement, Element>);\n }\n }\n };\n\n let text: string | JSX.Element = '';\n let more = 0;\n\n if (value !== undefined) {\n if (multiselect) {\n const selectedValues = value?.toString().split(',') || [];\n\n if (selectedValues.length === flattenedData.filter(item => !item.disabled).length) {\n text = texts.select.allOptionsSelected;\n } else {\n text = findByValue(flattenedData, selectedValues[0])?.text ?? '';\n more = selectedValues.length > 1 ? selectedValues.length - 1 : 0;\n }\n } else {\n const item = findByValue(flattenedData, value);\n\n if (item) {\n text = item.icon ? (\n <>\n {React.cloneElement(item.icon, {\n className: cn(item.icon.props.className, 'mr-1 -mt-px'),\n })}\n {item.text}\n </>\n ) : (\n item.text\n );\n }\n }\n }\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(flattenedData.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const handleButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (readOnly) {\n event.preventDefault();\n }\n };\n\n // select the value text if the select is readonly\n const handleButtonFocus = (event: React.FocusEvent<HTMLButtonElement>) => {\n if (readOnly) {\n const value = event.currentTarget.querySelector(':first-child');\n\n if (value) {\n window.getSelection()?.selectAllChildren?.(value);\n }\n }\n };\n\n const button: InternalButtonProps = {\n 'aria-haspopup': 'listbox' as const,\n 'aria-label': ariaLabel ? `${ariaLabel} ${text}` : undefined,\n 'aria-labelledby': ariaLabelledBy ? `${ariaLabelledBy} ${buttonId}` : undefined,\n 'aria-readonly': readOnly ? 'true' : undefined,\n disabled: disabled,\n id: buttonId,\n onClick: handleButtonClick,\n onFocus: handleButtonFocus,\n onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,\n tabIndex,\n type: 'button',\n };\n\n const listbox: InternalListboxProps = {\n ...otherProps,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n emptyValue,\n onBlur,\n onClick: handleListboxClick,\n onChange: event => {\n setInputValueByRef(inputRef.current, event.target.value);\n },\n onKeyDown: handleListboxKeyDown,\n ref: listboxInputRef,\n value,\n };\n\n const input: InternalInputProps = {\n onChange: handleInputChange,\n ref: inputRef,\n value: String(value ?? ''),\n };\n\n return {\n button,\n listbox,\n input,\n popover: {\n open,\n onOpenChange: setOpen,\n },\n text,\n more,\n };\n};\n"],"names":["_a","i","value"],"mappings":";;;;;;;AAyBO,MAAM,YAAY,CACrB;AAAA,EACI,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,OAAO,CAAC;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,IAAI;A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,CAAC,YAAY,CAAC,WAAW,sBAAsB;AAAA,IAC1D;AAAA,IACA,MAAM;AAAA,EACV;AAEA,QAAM,UAAgC;AAAA,IAClC,GAAG;AAAA,IACH,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,UAAU,CAAS,UAAA;AACf,yBAAmB,SAAS,SAAS,MAAM,OAAO,KAAK;AAAA,IAC3D;AAAA,IACA,WAAW;AAAA,IACX,KAAK;AAAA,IACL;AAAA,EACJ;AAEA,QAAM,QAA4B;AAAA,IAC9B,UAAU;AAAA,IACV,KAAK;AAAA,IACL,OAAO,OAAO,SAAS,EAAE;AAAA,EAC7B;AAEO,SAAA;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,MACL;AAAA,MACA,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;"}
|
|
1
|
+
{"version":3,"file":"useSelect.js","sources":["../../../src/components/Select/useSelect.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'clsx';\nimport { nanoid } from 'nanoid';\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover';\nimport { useLocalization } from '../Provider/Localization';\nimport { SelectProps } from './Select';\nimport { ListboxProps } from '../Listbox/Listbox';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport { setInputValueByRef, findByValue, useFlattenedData, sanitizeItem } from '../Listbox/util';\nimport { ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { createCustomEvent } from '../../utils/input';\n\ntype InternalButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\ntype InternalListboxProps = ListboxProps & { ref: React.ForwardedRef<HTMLInputElement> };\ntype InternalInputProps = React.InputHTMLAttributes<HTMLInputElement> & { ref: React.ForwardedRef<HTMLInputElement> };\n\ntype useSelect = React.HtmlHTMLAttributes<HTMLDivElement> & {\n button: InternalButtonProps;\n listbox: InternalListboxProps;\n input: InternalInputProps;\n popover: Pick<PopoverPrimitive.Root.Props, 'onOpenChange' | 'open'>;\n text: string | JSX.Element;\n more?: number;\n};\n\nexport const useSelect = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n multiselect,\n onBlur,\n onClick: _1,\n onChange,\n readOnly,\n tabIndex,\n value,\n ...otherProps\n }: SelectProps,\n ref: React.Ref<HTMLInputElement>\n): useSelect => {\n const { texts } = useLocalization();\n const flattenedData = useFlattenedData(data);\n const listboxInputRef = useMergedRef<HTMLInputElement>(ref);\n const [open, setOpen] = React.useState(false);\n const id = React.useMemo(() => nativeId || `select_${nanoid()}`, [nativeId]);\n const inputRef = React.useRef<HTMLInputElement>(null);\n const buttonId = `${id}-button`;\n // support 'escape' resetting to the value that was set when the listbox opened\n const [lastValue, setLastValue] = React.useState<ScrollableListItemValue | undefined>(value);\n\n React.useEffect(() => {\n setLastValue(value);\n }, [open]);\n\n React.useEffect(() => {\n if (value === undefined) {\n if (defaultValue !== undefined && findByValue(flattenedData, defaultValue)) {\n setInputValueByRef(inputRef.current, defaultValue);\n } else if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n } else if (!multiselect && !findByValue(flattenedData, value)) {\n if (emptyValue !== undefined) {\n setInputValueByRef(inputRef.current, emptyValue);\n } else if (data.length > 0) {\n setInputValueByRef(inputRef.current, data[0]?.value);\n }\n }\n }, []);\n\n // event handlers\n const handleButtonKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>): void => {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n switch (event.key) {\n case 'Escape': {\n event.preventDefault();\n if (lastValue !== undefined) {\n setInputValueByRef(listboxInputRef.current, lastValue);\n }\n\n setOpen(false);\n break;\n }\n\n case 'Tab':\n case 'Enter': {\n if (event.key !== 'Tab') {\n event.preventDefault();\n }\n setOpen(false);\n break;\n }\n\n default:\n }\n\n if (otherProps.onKeyDown) {\n otherProps.onKeyDown(event);\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>): void => {\n event.preventDefault();\n if (!multiselect) {\n setOpen(false);\n if (onBlur) {\n onBlur(createCustomEvent('blur') as unknown as React.FocusEvent<HTMLElement, Element>);\n }\n }\n };\n\n let text: string | JSX.Element = '';\n let more = 0;\n\n if (value !== undefined) {\n if (multiselect) {\n const selectedValues = value?.toString().split(',') || [];\n\n if (selectedValues.length === flattenedData.filter(item => !item.disabled).length) {\n text = texts.select.allOptionsSelected;\n } else {\n text = findByValue(flattenedData, selectedValues[0])?.text ?? '';\n more = selectedValues.length > 1 ? selectedValues.length - 1 : 0;\n }\n } else {\n const item = findByValue(flattenedData, value);\n\n if (item) {\n text = item.icon ? (\n <>\n {React.cloneElement(item.icon, {\n className: cn(item.icon.props.className, 'mr-1 -mt-px'),\n })}\n {item.text}\n </>\n ) : (\n item.text\n );\n }\n }\n }\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(flattenedData.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const handleButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n if (readOnly) {\n event.preventDefault();\n }\n };\n\n // select the value text if the select is readonly\n const handleButtonFocus = (event: React.FocusEvent<HTMLButtonElement>) => {\n if (readOnly) {\n const value = event.currentTarget.querySelector(':first-child');\n\n if (value) {\n window.getSelection()?.selectAllChildren?.(value);\n }\n }\n };\n\n const button: InternalButtonProps = {\n 'aria-haspopup': 'listbox' as const,\n 'aria-label': ariaLabel ? `${ariaLabel} ${text}` : undefined,\n 'aria-labelledby': ariaLabelledBy ? `${ariaLabelledBy} ${buttonId}` : undefined,\n 'aria-readonly': readOnly ? 'true' : undefined,\n disabled: disabled,\n id: buttonId,\n onClick: handleButtonClick,\n onFocus: handleButtonFocus,\n onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,\n tabIndex,\n type: 'button',\n };\n\n const listbox: InternalListboxProps = {\n ...otherProps,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n emptyValue,\n onBlur,\n onClick: handleListboxClick,\n onChange: event => {\n setInputValueByRef(inputRef.current, event.target.value);\n },\n onKeyDown: handleListboxKeyDown,\n ref: listboxInputRef,\n value,\n };\n\n const input: InternalInputProps = {\n onChange: handleInputChange,\n ref: inputRef,\n value: String(value ?? ''),\n };\n\n return {\n button,\n listbox,\n input,\n popover: {\n open,\n onOpenChange: setOpen,\n },\n text,\n more,\n };\n};\n"],"names":["_a","i","value"],"mappings":";;;;;;;AAyBO,MAAM,YAAY,CACrB;AAAA,EACI,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,OAAO,CAAC;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,IAAI;AAAA,EACJ;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACP,GACA,QACY;;AACN,QAAA,EAAE,MAAM,IAAI,gBAAgB;AAC5B,QAAA,gBAAgB,iBAAiB,IAAI;AACrC,QAAA,kBAAkB,aAA+B,GAAG;AAC1D,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,KAAK;AACtC,QAAA,KAAK,MAAM,QAAQ,MAAM,YAAY,UAAU,OAAQ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A,IACL;AAAA,EACJ;AAEA,QAAM,QAA4B;AAAA,IAC9B,UAAU;AAAA,IACV,KAAK;AAAA,IACL,OAAO,OAAO,SAAS,EAAE;AAAA,EAC7B;AAEO,SAAA;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,MACL;AAAA,MACA,cAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;"}
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,6 @@ const LinkButton = require("./components/Actions/LinkButton/LinkButton.cjs");
|
|
|
33
33
|
const List = require("./components/List/List.cjs");
|
|
34
34
|
const Listbox = require("./components/Listbox/Listbox.cjs");
|
|
35
35
|
const Menu = require("./components/Menu/Menu.cjs");
|
|
36
|
-
const Navigation = require("./components/Navigation/Navigation.cjs");
|
|
37
36
|
const OverflowGroup = require("./components/OverflowGroup/OverflowGroup.cjs");
|
|
38
37
|
const Pagination = require("./components/Pagination/Pagination.cjs");
|
|
39
38
|
const Popover = require("./components/Popover/Popover.cjs");
|
|
@@ -133,7 +132,6 @@ exports.List = List.List;
|
|
|
133
132
|
exports.Listbox = Listbox.Listbox;
|
|
134
133
|
exports.MultiListbox = Listbox.MultiListbox;
|
|
135
134
|
exports.Menu = Menu.Menu;
|
|
136
|
-
exports.Navigation = Navigation.Navigation;
|
|
137
135
|
exports.OverflowGroup = OverflowGroup.OverflowGroup;
|
|
138
136
|
exports.Pagination = Pagination.Pagination;
|
|
139
137
|
exports.Popover = Popover.Popover;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,6 @@ export * from './components/Actions/LinkButton/LinkButton';
|
|
|
29
29
|
export * from './components/List/List';
|
|
30
30
|
export * from './components/Listbox/Listbox';
|
|
31
31
|
export * from './components/Menu/Menu';
|
|
32
|
-
export * from './components/Navigation/Navigation';
|
|
33
32
|
export * from './components/OverflowGroup/OverflowGroup';
|
|
34
33
|
export * from './components/Pagination/Pagination';
|
|
35
34
|
export * from './components/Popover/Popover';
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,6 @@ import { LinkButton } from "./components/Actions/LinkButton/LinkButton.js";
|
|
|
31
31
|
import { List } from "./components/List/List.js";
|
|
32
32
|
import { Listbox, MultiListbox } from "./components/Listbox/Listbox.js";
|
|
33
33
|
import { Menu } from "./components/Menu/Menu.js";
|
|
34
|
-
import { Navigation } from "./components/Navigation/Navigation.js";
|
|
35
34
|
import { OverflowGroup } from "./components/OverflowGroup/OverflowGroup.js";
|
|
36
35
|
import { Pagination } from "./components/Pagination/Pagination.js";
|
|
37
36
|
import { Popover } from "./components/Popover/Popover.js";
|
|
@@ -145,7 +144,6 @@ export {
|
|
|
145
144
|
LocalizationProvider,
|
|
146
145
|
Menu,
|
|
147
146
|
MultiListbox,
|
|
148
|
-
Navigation,
|
|
149
147
|
Navigation2,
|
|
150
148
|
OverflowGroup,
|
|
151
149
|
PaginatedTable,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/taco.css
CHANGED
|
@@ -487,44 +487,6 @@ table.yt-table tbody.yt-table__body tr.yt-table__row td.yt-table__cell {
|
|
|
487
487
|
[data-taco='list-group'] > [data-taco='list-item-collapsible']:not(:last-child) > div {
|
|
488
488
|
@apply rounded-b-none;
|
|
489
489
|
}
|
|
490
|
-
.yt-navigation__item a,
|
|
491
|
-
.yt-navigation__item .yt-navigation__item__postfix {
|
|
492
|
-
@apply text-black;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
.yt-navigation__item .yt-navigation__item__prefix [data-taco='icon'] {
|
|
496
|
-
@apply -mt-1 -mb-1 text-xs;
|
|
497
|
-
margin-left: -0.375rem;
|
|
498
|
-
margin-right: 0.15rem;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
.yt-navigation__item:hover,
|
|
502
|
-
.yt-navigation__item:hover a,
|
|
503
|
-
.yt-navigation__item:hover .yt-navigation__item__postfix,
|
|
504
|
-
.yt-navigation__item--active,
|
|
505
|
-
.yt-navigation__item--active a,
|
|
506
|
-
.yt-navigation__item--active .yt-navigation__item__postfix {
|
|
507
|
-
@apply text-blue-500;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
.yt-navigation__item--dropping,
|
|
511
|
-
.yt-navigation__item--dropping a,
|
|
512
|
-
.yt-navigation__item--dropping .yt-navigation__item__postfix {
|
|
513
|
-
@apply text-white;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
.yt-navigation__item:hover .yt-navigation__item__postfix [data-taco='badge']:not(.h-2),
|
|
517
|
-
.yt-navigation__item--active .yt-navigation__item__postfix [data-taco='badge']:not(.h-2) {
|
|
518
|
-
@apply yt-blue-inverted;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
.yt-navigation__item--dropping > * {
|
|
522
|
-
@apply pointer-events-none;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
.yt-navigation__item--dropping .yt-navigation__item__postfix [data-taco='badge'] {
|
|
526
|
-
@apply border-white text-white;
|
|
527
|
-
}
|
|
528
490
|
.yt-toast:hover [data-taco='progress-bar'] {
|
|
529
491
|
animation-play-state: paused;
|
|
530
492
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/taco",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-docs-publishing.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"@dnd-kit/sortable": "^7.0.2",
|
|
48
48
|
"@dnd-kit/utilities": "^3.2.2",
|
|
49
49
|
"@economic/taco-tokens": "^3.0.0",
|
|
50
|
-
"@radix-ui/react-popover": "1.0.2",
|
|
51
50
|
"@radix-ui/react-scroll-area": "1.2.10",
|
|
52
51
|
"@react-aria/focus": "^3.19.0",
|
|
53
52
|
"@react-aria/interactions": "^3.12.0",
|
|
@@ -102,5 +101,5 @@
|
|
|
102
101
|
"optionalDependencies": {
|
|
103
102
|
"@rollup/rollup-linux-x64-gnu": "^4.62.2"
|
|
104
103
|
},
|
|
105
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "ce4139246da7ea295a926013d445e32d6c1869b8"
|
|
106
105
|
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const React = require("react");
|
|
4
|
-
const cn = require("clsx");
|
|
5
|
-
const Treeview = require("../Treeview/Treeview.cjs");
|
|
6
|
-
const Icon = require("../Icon/Icon.cjs");
|
|
7
|
-
const useDropTarget = require("../../utils/hooks/useDropTarget.cjs");
|
|
8
|
-
const useMergedRef = require("../../hooks/useMergedRef.cjs");
|
|
9
|
-
;/* empty css */
|
|
10
|
-
const Item = React.forwardRef(function Item2(props, ref) {
|
|
11
|
-
const { active, children, onDrop, postfix, prefix, role, ...otherProps } = props;
|
|
12
|
-
const proxyRef = useMergedRef.useMergedRef(ref);
|
|
13
|
-
const [isDraggedOver, dropTargetProps] = useDropTarget.useDropTarget(onDrop);
|
|
14
|
-
const isTreeitem = role === "treeitem";
|
|
15
|
-
const className = cn(
|
|
16
|
-
"yt-navigation__item cursor-pointer",
|
|
17
|
-
{
|
|
18
|
-
"w-full mb-px py-1 px-3 flex items-center hover:bg-gray-300": isTreeitem,
|
|
19
|
-
"bg-white w-full h-10 px-3 flex-shrink-0 flex items-center justify-between cursor-pointer": !isTreeitem,
|
|
20
|
-
"yt-navigation__item--active": active && !isDraggedOver,
|
|
21
|
-
"bg-gray-300": isTreeitem && active && !isDraggedOver,
|
|
22
|
-
"yt-navigation__item--dropping bg-blue-500": isDraggedOver
|
|
23
|
-
},
|
|
24
|
-
props.className
|
|
25
|
-
);
|
|
26
|
-
const handleClick = (event) => {
|
|
27
|
-
if (event.target instanceof HTMLAnchorElement || event.target instanceof HTMLButtonElement) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (proxyRef.current) {
|
|
31
|
-
proxyRef.current.click();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
return /* @__PURE__ */ React.createElement("span", { ...dropTargetProps, className, onClick: handleClick, role }, prefix && /* @__PURE__ */ React.createElement("span", { className: "yt-navigation__item__prefix flex items-center" }, prefix), /* @__PURE__ */ React.createElement("a", { ...otherProps, className: "block flex-grow truncate", ref: proxyRef }, children), postfix && /* @__PURE__ */ React.createElement("span", { className: "yt-navigation__item__postfix ml-1" }, postfix));
|
|
35
|
-
});
|
|
36
|
-
const Panel = React.forwardRef(function Panel2(props, ref) {
|
|
37
|
-
return /* @__PURE__ */ React.createElement("div", { ...props, className: cn("w-full bg-white p-3", props.className), ref });
|
|
38
|
-
});
|
|
39
|
-
const MenuGroup = React.forwardRef(function MenuGroup2(props, ref) {
|
|
40
|
-
const className = cn(
|
|
41
|
-
"flex-shrink-0 space-y-1 outline-none",
|
|
42
|
-
{
|
|
43
|
-
"bg-white pb-2": props.fixed
|
|
44
|
-
},
|
|
45
|
-
typeof props.className === "function" ? props.className(false) : props.className
|
|
46
|
-
);
|
|
47
|
-
const title = (expanded) => {
|
|
48
|
-
const className2 = cn("bg-white h-10 pl-3 pr-1 flex items-center justify-between w-full", {
|
|
49
|
-
"mb-1": expanded,
|
|
50
|
-
"cursor-pointer hover:text-blue-500": !props.fixed
|
|
51
|
-
});
|
|
52
|
-
return /* @__PURE__ */ React.createElement("span", { className: className2 }, typeof props.title === "function" ? props.title(expanded) : props.title, !props.fixed && /* @__PURE__ */ React.createElement(Icon.Icon, { name: expanded ? "chevron-up" : "chevron-down" }));
|
|
53
|
-
};
|
|
54
|
-
return /* @__PURE__ */ React.createElement(Treeview.Treeview.Group, { ...props, className, title, ref });
|
|
55
|
-
});
|
|
56
|
-
const Menu = React.forwardRef(function Menu2(props, ref) {
|
|
57
|
-
const scrollableAreas = React.useMemo(() => {
|
|
58
|
-
const scrollableAreas2 = [];
|
|
59
|
-
const children = React.Children.toArray(props.children).filter(
|
|
60
|
-
(child) => !!child
|
|
61
|
-
);
|
|
62
|
-
children.forEach((child) => {
|
|
63
|
-
if (child.props.fixed) {
|
|
64
|
-
scrollableAreas2.push(child);
|
|
65
|
-
} else {
|
|
66
|
-
const x = scrollableAreas2[scrollableAreas2.length - 1];
|
|
67
|
-
if (Array.isArray(x)) {
|
|
68
|
-
x.push(child);
|
|
69
|
-
} else {
|
|
70
|
-
scrollableAreas2.push([child]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return scrollableAreas2;
|
|
75
|
-
}, [props.children]);
|
|
76
|
-
return /* @__PURE__ */ React.createElement(
|
|
77
|
-
Treeview.Treeview,
|
|
78
|
-
{
|
|
79
|
-
...props,
|
|
80
|
-
className: cn("flex flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto", props.className),
|
|
81
|
-
ref
|
|
82
|
-
},
|
|
83
|
-
scrollableAreas.map(
|
|
84
|
-
(area, i) => Array.isArray(area) ? /* @__PURE__ */ React.createElement(
|
|
85
|
-
"div",
|
|
86
|
-
{
|
|
87
|
-
className: "flex h-0 flex-auto flex-shrink-0 flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto",
|
|
88
|
-
key: i
|
|
89
|
-
},
|
|
90
|
-
area
|
|
91
|
-
) : area
|
|
92
|
-
)
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
Menu.Group = MenuGroup;
|
|
96
|
-
const Navigation = React.forwardRef(function Navigation2(props, ref) {
|
|
97
|
-
const { children, ...otherProps } = props;
|
|
98
|
-
const className = cn("h-full flex flex-col bg-gray-100 divide-y-2 divide-gray-100", props.className);
|
|
99
|
-
return /* @__PURE__ */ React.createElement("div", { ...otherProps, className, "data-taco": "navigation", ref }, children);
|
|
100
|
-
});
|
|
101
|
-
Navigation.Menu = Menu;
|
|
102
|
-
Navigation.Item = Item;
|
|
103
|
-
Navigation.Panel = Panel;
|
|
104
|
-
exports.Navigation = Navigation;
|
|
105
|
-
//# sourceMappingURL=Navigation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Navigation.cjs","sources":["../../../src/components/Navigation/Navigation.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { TreeviewProps, Treeview, TreeviewGroupProps, TreeviewItemProps } from '../Treeview/Treeview';\nimport { Icon } from '../Icon/Icon';\nimport { useDropTarget } from '../../utils/hooks/useDropTarget';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport './Navigation.css';\n\n// Item\nexport type NavigationItemProps = Omit<TreeviewItemProps, 'prefix'> & {\n /** Change the style to indicate the link is selected */\n active?: boolean;\n /** Handler to be used when dropping a dragged element over the navigation link */\n onDrop?: React.DragEventHandler;\n /**\n * Small amount of information placed next to the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a relevant information of the link,\n * for e.g. the number of unread notifications\n */\n postfix?: React.ReactNode;\n /**\n * Small amount of information placed before the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a feedback for user,\n * for e.g. display some sort of visual informational state or a relevant icon.\n */\n prefix?: React.ReactNode;\n /** Target of the link */\n target?: string;\n};\n\nconst Item = React.forwardRef(function Item(props: NavigationItemProps, ref: React.Ref<HTMLAnchorElement>) {\n const { active, children, onDrop, postfix, prefix, role, ...otherProps } = props;\n const proxyRef = useMergedRef<HTMLAnchorElement>(ref);\n const [isDraggedOver, dropTargetProps] = useDropTarget(onDrop);\n const isTreeitem = role === 'treeitem';\n const className = cn(\n 'yt-navigation__item cursor-pointer',\n {\n 'w-full mb-px py-1 px-3 flex items-center hover:bg-gray-300': isTreeitem,\n 'bg-white w-full h-10 px-3 flex-shrink-0 flex items-center justify-between cursor-pointer': !isTreeitem,\n 'yt-navigation__item--active': active && !isDraggedOver,\n 'bg-gray-300': isTreeitem && active && !isDraggedOver,\n 'yt-navigation__item--dropping bg-blue-500': isDraggedOver,\n },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLSpanElement>): void => {\n if (event.target instanceof HTMLAnchorElement || event.target instanceof HTMLButtonElement) {\n return;\n }\n\n if (proxyRef.current) {\n proxyRef.current.click();\n }\n };\n\n return (\n <span {...dropTargetProps} className={className} onClick={handleClick} role={role}>\n {prefix && <span className=\"yt-navigation__item__prefix flex items-center\">{prefix}</span>}\n <a {...otherProps} className=\"block flex-grow truncate\" ref={proxyRef}>\n {children}\n </a>\n {postfix && <span className=\"yt-navigation__item__postfix ml-1\">{postfix}</span>}\n </span>\n );\n});\n\n// Panel\nexport type NavigationPanelProps = React.HTMLAttributes<HTMLDivElement>;\n\nconst Panel = React.forwardRef(function Panel(props: NavigationPanelProps, ref: React.Ref<HTMLDivElement>) {\n return <div {...props} className={cn('w-full bg-white p-3', props.className)} ref={ref} />;\n});\n\n// Group\nexport type NavigationMenuGroupProps = TreeviewGroupProps;\n\nconst MenuGroup = React.forwardRef(function MenuGroup(props: NavigationMenuGroupProps, ref: React.Ref<HTMLDivElement>) {\n const className = cn(\n 'flex-shrink-0 space-y-1 outline-none',\n {\n 'bg-white pb-2': props.fixed,\n },\n typeof props.className === 'function' ? props.className(false) : props.className\n );\n const title = (expanded: boolean): JSX.Element => {\n const className = cn('bg-white h-10 pl-3 pr-1 flex items-center justify-between w-full', {\n 'mb-1': expanded,\n 'cursor-pointer hover:text-blue-500': !props.fixed,\n });\n\n return (\n <span className={className}>\n {typeof props.title === 'function' ? props.title(expanded) : props.title}\n {!props.fixed && <Icon name={expanded ? 'chevron-up' : 'chevron-down'} />}\n </span>\n );\n };\n\n return <Treeview.Group {...props} className={className} title={title} ref={ref} />;\n});\n\n// Menu\nexport type NavigationMenuProps = React.PropsWithChildren<TreeviewProps>;\n\nexport type ForwardedNavigationMenuWithStatics = React.ForwardRefExoticComponent<\n NavigationMenuProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Expandable region reprezenting a group of related links */\n Group: React.ForwardRefExoticComponent<NavigationMenuGroupProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nconst Menu = React.forwardRef(function Menu(props: NavigationMenuProps, ref: React.Ref<HTMLDivElement>) {\n const scrollableAreas = React.useMemo(() => {\n const scrollableAreas: React.ReactNode[] = [];\n\n const children = React.Children.toArray(props.children).filter(\n child => !!child\n ) as React.ReactElement<NavigationMenuGroupProps>[];\n\n children.forEach(child => {\n if (child.props.fixed) {\n scrollableAreas.push(child);\n } else {\n const x = scrollableAreas[scrollableAreas.length - 1];\n if (Array.isArray(x)) {\n x.push(child);\n } else {\n scrollableAreas.push([child]);\n }\n }\n });\n\n return scrollableAreas;\n }, [props.children]);\n\n return (\n <Treeview\n {...props}\n className={cn('flex flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto', props.className)}\n ref={ref}>\n {scrollableAreas.map((area, i) =>\n Array.isArray(area) ? (\n <div\n className=\"flex h-0 flex-auto flex-shrink-0 flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto\"\n key={i}>\n {area}\n </div>\n ) : (\n area\n )\n )}\n </Treeview>\n );\n}) as ForwardedNavigationMenuWithStatics;\n\nMenu.Group = MenuGroup;\n\n// Navigation\nexport type NavigationProps = React.HTMLAttributes<HTMLDivElement>;\n\nexport type ForwardedNavigationWithStatics = React.ForwardRefExoticComponent<\n NavigationProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Navigation link */\n Item: React.ForwardRefExoticComponent<NavigationItemProps & React.RefAttributes<HTMLAnchorElement>>;\n /**\n * Container for the expandable groups that hold navigation links.\n * Should be used as a direct child of Navigation component, e.g. `Navigation.Menu`.\n * Should have the menu groups as a direct child, e.g. `Navigation.Menu.Group`\n */\n Menu: ForwardedNavigationMenuWithStatics;\n /**\n * Isolated container within the Navigation.\n * This can be used to create a region in the Navigation that is usually not scrollable, nor expandable,\n * containing useful information for user and quick actions\n */\n Panel: React.ForwardRefExoticComponent<NavigationPanelProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nexport const Navigation = React.forwardRef(function Navigation(props: NavigationProps, ref: React.Ref<HTMLDivElement>) {\n const { children, ...otherProps } = props;\n const className = cn('h-full flex flex-col bg-gray-100 divide-y-2 divide-gray-100', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"navigation\" ref={ref}>\n {children}\n </div>\n );\n}) as ForwardedNavigationWithStatics;\n\nNavigation.Menu = Menu;\nNavigation.Item = Item;\nNavigation.Panel = Panel;\n"],"names":["Item","useMergedRef","useDropTarget","Panel","MenuGroup","className","Icon","Treeview","Menu","scrollableAreas","Navigation"],"mappings":";;;;;;;;;AAgCA,MAAM,OAAO,MAAM,WAAW,SAASA,MAAK,OAA4B,KAAmC;AACjG,QAAA,EAAE,QAAQ,UAAU,QAAQ,SAAS,QAAQ,MAAM,GAAG,WAAA,IAAe;AACrE,QAAA,WAAWC,0BAAgC,GAAG;AACpD,QAAM,CAAC,eAAe,eAAe,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A,IAGL;AAAA,IAAA;AAAA,EAGZ;AAER,CAAC;AAED,KAAK,QAAQ;AAwBN,MAAM,aAAa,MAAM,WAAW,SAASG,YAAW,OAAwB,KAAgC;AACnH,QAAM,EAAE,UAAU,GAAG,WAAA,IAAe;AACpC,QAAM,YAAY,GAAG,+DAA+D,MAAM,SAAS;AAG/F,SAAA,sBAAA,cAAC,SAAK,GAAG,YAAY,WAAsB,aAAU,cAAa,OAC7D,QACL;AAER,CAAC;AAED,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,QAAQ;;"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { TreeviewProps, TreeviewGroupProps, TreeviewItemProps } from '../Treeview/Treeview';
|
|
3
|
-
export type NavigationItemProps = Omit<TreeviewItemProps, 'prefix'> & {
|
|
4
|
-
/** Change the style to indicate the link is selected */
|
|
5
|
-
active?: boolean;
|
|
6
|
-
/** Handler to be used when dropping a dragged element over the navigation link */
|
|
7
|
-
onDrop?: React.DragEventHandler;
|
|
8
|
-
/**
|
|
9
|
-
* Small amount of information placed next to the text of the link.
|
|
10
|
-
* This can be any valid react element, for e.g. a `span`.
|
|
11
|
-
* Should be used to indicate a relevant information of the link,
|
|
12
|
-
* for e.g. the number of unread notifications
|
|
13
|
-
*/
|
|
14
|
-
postfix?: React.ReactNode;
|
|
15
|
-
/**
|
|
16
|
-
* Small amount of information placed before the text of the link.
|
|
17
|
-
* This can be any valid react element, for e.g. a `span`.
|
|
18
|
-
* Should be used to indicate a feedback for user,
|
|
19
|
-
* for e.g. display some sort of visual informational state or a relevant icon.
|
|
20
|
-
*/
|
|
21
|
-
prefix?: React.ReactNode;
|
|
22
|
-
/** Target of the link */
|
|
23
|
-
target?: string;
|
|
24
|
-
};
|
|
25
|
-
export type NavigationPanelProps = React.HTMLAttributes<HTMLDivElement>;
|
|
26
|
-
export type NavigationMenuGroupProps = TreeviewGroupProps;
|
|
27
|
-
export type NavigationMenuProps = React.PropsWithChildren<TreeviewProps>;
|
|
28
|
-
export type ForwardedNavigationMenuWithStatics = React.ForwardRefExoticComponent<NavigationMenuProps & React.RefAttributes<HTMLDivElement>> & {
|
|
29
|
-
/** Expandable region reprezenting a group of related links */
|
|
30
|
-
Group: React.ForwardRefExoticComponent<NavigationMenuGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
31
|
-
};
|
|
32
|
-
export type NavigationProps = React.HTMLAttributes<HTMLDivElement>;
|
|
33
|
-
export type ForwardedNavigationWithStatics = React.ForwardRefExoticComponent<NavigationProps & React.RefAttributes<HTMLDivElement>> & {
|
|
34
|
-
/** Navigation link */
|
|
35
|
-
Item: React.ForwardRefExoticComponent<NavigationItemProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
36
|
-
/**
|
|
37
|
-
* Container for the expandable groups that hold navigation links.
|
|
38
|
-
* Should be used as a direct child of Navigation component, e.g. `Navigation.Menu`.
|
|
39
|
-
* Should have the menu groups as a direct child, e.g. `Navigation.Menu.Group`
|
|
40
|
-
*/
|
|
41
|
-
Menu: ForwardedNavigationMenuWithStatics;
|
|
42
|
-
/**
|
|
43
|
-
* Isolated container within the Navigation.
|
|
44
|
-
* This can be used to create a region in the Navigation that is usually not scrollable, nor expandable,
|
|
45
|
-
* containing useful information for user and quick actions
|
|
46
|
-
*/
|
|
47
|
-
Panel: React.ForwardRefExoticComponent<NavigationPanelProps & React.RefAttributes<HTMLDivElement>>;
|
|
48
|
-
};
|
|
49
|
-
export declare const Navigation: ForwardedNavigationWithStatics;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import React__default from "react";
|
|
2
|
-
import cn from "clsx";
|
|
3
|
-
import { Treeview } from "../Treeview/Treeview.js";
|
|
4
|
-
import { Icon } from "../Icon/Icon.js";
|
|
5
|
-
import { useDropTarget } from "../../utils/hooks/useDropTarget.js";
|
|
6
|
-
import { useMergedRef } from "../../hooks/useMergedRef.js";
|
|
7
|
-
/* empty css */
|
|
8
|
-
const Item = React__default.forwardRef(function Item2(props, ref) {
|
|
9
|
-
const { active, children, onDrop, postfix, prefix, role, ...otherProps } = props;
|
|
10
|
-
const proxyRef = useMergedRef(ref);
|
|
11
|
-
const [isDraggedOver, dropTargetProps] = useDropTarget(onDrop);
|
|
12
|
-
const isTreeitem = role === "treeitem";
|
|
13
|
-
const className = cn(
|
|
14
|
-
"yt-navigation__item cursor-pointer",
|
|
15
|
-
{
|
|
16
|
-
"w-full mb-px py-1 px-3 flex items-center hover:bg-gray-300": isTreeitem,
|
|
17
|
-
"bg-white w-full h-10 px-3 flex-shrink-0 flex items-center justify-between cursor-pointer": !isTreeitem,
|
|
18
|
-
"yt-navigation__item--active": active && !isDraggedOver,
|
|
19
|
-
"bg-gray-300": isTreeitem && active && !isDraggedOver,
|
|
20
|
-
"yt-navigation__item--dropping bg-blue-500": isDraggedOver
|
|
21
|
-
},
|
|
22
|
-
props.className
|
|
23
|
-
);
|
|
24
|
-
const handleClick = (event) => {
|
|
25
|
-
if (event.target instanceof HTMLAnchorElement || event.target instanceof HTMLButtonElement) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (proxyRef.current) {
|
|
29
|
-
proxyRef.current.click();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
return /* @__PURE__ */ React__default.createElement("span", { ...dropTargetProps, className, onClick: handleClick, role }, prefix && /* @__PURE__ */ React__default.createElement("span", { className: "yt-navigation__item__prefix flex items-center" }, prefix), /* @__PURE__ */ React__default.createElement("a", { ...otherProps, className: "block flex-grow truncate", ref: proxyRef }, children), postfix && /* @__PURE__ */ React__default.createElement("span", { className: "yt-navigation__item__postfix ml-1" }, postfix));
|
|
33
|
-
});
|
|
34
|
-
const Panel = React__default.forwardRef(function Panel2(props, ref) {
|
|
35
|
-
return /* @__PURE__ */ React__default.createElement("div", { ...props, className: cn("w-full bg-white p-3", props.className), ref });
|
|
36
|
-
});
|
|
37
|
-
const MenuGroup = React__default.forwardRef(function MenuGroup2(props, ref) {
|
|
38
|
-
const className = cn(
|
|
39
|
-
"flex-shrink-0 space-y-1 outline-none",
|
|
40
|
-
{
|
|
41
|
-
"bg-white pb-2": props.fixed
|
|
42
|
-
},
|
|
43
|
-
typeof props.className === "function" ? props.className(false) : props.className
|
|
44
|
-
);
|
|
45
|
-
const title = (expanded) => {
|
|
46
|
-
const className2 = cn("bg-white h-10 pl-3 pr-1 flex items-center justify-between w-full", {
|
|
47
|
-
"mb-1": expanded,
|
|
48
|
-
"cursor-pointer hover:text-blue-500": !props.fixed
|
|
49
|
-
});
|
|
50
|
-
return /* @__PURE__ */ React__default.createElement("span", { className: className2 }, typeof props.title === "function" ? props.title(expanded) : props.title, !props.fixed && /* @__PURE__ */ React__default.createElement(Icon, { name: expanded ? "chevron-up" : "chevron-down" }));
|
|
51
|
-
};
|
|
52
|
-
return /* @__PURE__ */ React__default.createElement(Treeview.Group, { ...props, className, title, ref });
|
|
53
|
-
});
|
|
54
|
-
const Menu = React__default.forwardRef(function Menu2(props, ref) {
|
|
55
|
-
const scrollableAreas = React__default.useMemo(() => {
|
|
56
|
-
const scrollableAreas2 = [];
|
|
57
|
-
const children = React__default.Children.toArray(props.children).filter(
|
|
58
|
-
(child) => !!child
|
|
59
|
-
);
|
|
60
|
-
children.forEach((child) => {
|
|
61
|
-
if (child.props.fixed) {
|
|
62
|
-
scrollableAreas2.push(child);
|
|
63
|
-
} else {
|
|
64
|
-
const x = scrollableAreas2[scrollableAreas2.length - 1];
|
|
65
|
-
if (Array.isArray(x)) {
|
|
66
|
-
x.push(child);
|
|
67
|
-
} else {
|
|
68
|
-
scrollableAreas2.push([child]);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return scrollableAreas2;
|
|
73
|
-
}, [props.children]);
|
|
74
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
75
|
-
Treeview,
|
|
76
|
-
{
|
|
77
|
-
...props,
|
|
78
|
-
className: cn("flex flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto", props.className),
|
|
79
|
-
ref
|
|
80
|
-
},
|
|
81
|
-
scrollableAreas.map(
|
|
82
|
-
(area, i) => Array.isArray(area) ? /* @__PURE__ */ React__default.createElement(
|
|
83
|
-
"div",
|
|
84
|
-
{
|
|
85
|
-
className: "flex h-0 flex-auto flex-shrink-0 flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto",
|
|
86
|
-
key: i
|
|
87
|
-
},
|
|
88
|
-
area
|
|
89
|
-
) : area
|
|
90
|
-
)
|
|
91
|
-
);
|
|
92
|
-
});
|
|
93
|
-
Menu.Group = MenuGroup;
|
|
94
|
-
const Navigation = React__default.forwardRef(function Navigation2(props, ref) {
|
|
95
|
-
const { children, ...otherProps } = props;
|
|
96
|
-
const className = cn("h-full flex flex-col bg-gray-100 divide-y-2 divide-gray-100", props.className);
|
|
97
|
-
return /* @__PURE__ */ React__default.createElement("div", { ...otherProps, className, "data-taco": "navigation", ref }, children);
|
|
98
|
-
});
|
|
99
|
-
Navigation.Menu = Menu;
|
|
100
|
-
Navigation.Item = Item;
|
|
101
|
-
Navigation.Panel = Panel;
|
|
102
|
-
export {
|
|
103
|
-
Navigation
|
|
104
|
-
};
|
|
105
|
-
//# sourceMappingURL=Navigation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Navigation.js","sources":["../../../src/components/Navigation/Navigation.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { TreeviewProps, Treeview, TreeviewGroupProps, TreeviewItemProps } from '../Treeview/Treeview';\nimport { Icon } from '../Icon/Icon';\nimport { useDropTarget } from '../../utils/hooks/useDropTarget';\nimport { useMergedRef } from '../../hooks/useMergedRef';\nimport './Navigation.css';\n\n// Item\nexport type NavigationItemProps = Omit<TreeviewItemProps, 'prefix'> & {\n /** Change the style to indicate the link is selected */\n active?: boolean;\n /** Handler to be used when dropping a dragged element over the navigation link */\n onDrop?: React.DragEventHandler;\n /**\n * Small amount of information placed next to the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a relevant information of the link,\n * for e.g. the number of unread notifications\n */\n postfix?: React.ReactNode;\n /**\n * Small amount of information placed before the text of the link.\n * This can be any valid react element, for e.g. a `span`.\n * Should be used to indicate a feedback for user,\n * for e.g. display some sort of visual informational state or a relevant icon.\n */\n prefix?: React.ReactNode;\n /** Target of the link */\n target?: string;\n};\n\nconst Item = React.forwardRef(function Item(props: NavigationItemProps, ref: React.Ref<HTMLAnchorElement>) {\n const { active, children, onDrop, postfix, prefix, role, ...otherProps } = props;\n const proxyRef = useMergedRef<HTMLAnchorElement>(ref);\n const [isDraggedOver, dropTargetProps] = useDropTarget(onDrop);\n const isTreeitem = role === 'treeitem';\n const className = cn(\n 'yt-navigation__item cursor-pointer',\n {\n 'w-full mb-px py-1 px-3 flex items-center hover:bg-gray-300': isTreeitem,\n 'bg-white w-full h-10 px-3 flex-shrink-0 flex items-center justify-between cursor-pointer': !isTreeitem,\n 'yt-navigation__item--active': active && !isDraggedOver,\n 'bg-gray-300': isTreeitem && active && !isDraggedOver,\n 'yt-navigation__item--dropping bg-blue-500': isDraggedOver,\n },\n props.className\n );\n\n const handleClick = (event: React.MouseEvent<HTMLSpanElement>): void => {\n if (event.target instanceof HTMLAnchorElement || event.target instanceof HTMLButtonElement) {\n return;\n }\n\n if (proxyRef.current) {\n proxyRef.current.click();\n }\n };\n\n return (\n <span {...dropTargetProps} className={className} onClick={handleClick} role={role}>\n {prefix && <span className=\"yt-navigation__item__prefix flex items-center\">{prefix}</span>}\n <a {...otherProps} className=\"block flex-grow truncate\" ref={proxyRef}>\n {children}\n </a>\n {postfix && <span className=\"yt-navigation__item__postfix ml-1\">{postfix}</span>}\n </span>\n );\n});\n\n// Panel\nexport type NavigationPanelProps = React.HTMLAttributes<HTMLDivElement>;\n\nconst Panel = React.forwardRef(function Panel(props: NavigationPanelProps, ref: React.Ref<HTMLDivElement>) {\n return <div {...props} className={cn('w-full bg-white p-3', props.className)} ref={ref} />;\n});\n\n// Group\nexport type NavigationMenuGroupProps = TreeviewGroupProps;\n\nconst MenuGroup = React.forwardRef(function MenuGroup(props: NavigationMenuGroupProps, ref: React.Ref<HTMLDivElement>) {\n const className = cn(\n 'flex-shrink-0 space-y-1 outline-none',\n {\n 'bg-white pb-2': props.fixed,\n },\n typeof props.className === 'function' ? props.className(false) : props.className\n );\n const title = (expanded: boolean): JSX.Element => {\n const className = cn('bg-white h-10 pl-3 pr-1 flex items-center justify-between w-full', {\n 'mb-1': expanded,\n 'cursor-pointer hover:text-blue-500': !props.fixed,\n });\n\n return (\n <span className={className}>\n {typeof props.title === 'function' ? props.title(expanded) : props.title}\n {!props.fixed && <Icon name={expanded ? 'chevron-up' : 'chevron-down'} />}\n </span>\n );\n };\n\n return <Treeview.Group {...props} className={className} title={title} ref={ref} />;\n});\n\n// Menu\nexport type NavigationMenuProps = React.PropsWithChildren<TreeviewProps>;\n\nexport type ForwardedNavigationMenuWithStatics = React.ForwardRefExoticComponent<\n NavigationMenuProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Expandable region reprezenting a group of related links */\n Group: React.ForwardRefExoticComponent<NavigationMenuGroupProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nconst Menu = React.forwardRef(function Menu(props: NavigationMenuProps, ref: React.Ref<HTMLDivElement>) {\n const scrollableAreas = React.useMemo(() => {\n const scrollableAreas: React.ReactNode[] = [];\n\n const children = React.Children.toArray(props.children).filter(\n child => !!child\n ) as React.ReactElement<NavigationMenuGroupProps>[];\n\n children.forEach(child => {\n if (child.props.fixed) {\n scrollableAreas.push(child);\n } else {\n const x = scrollableAreas[scrollableAreas.length - 1];\n if (Array.isArray(x)) {\n x.push(child);\n } else {\n scrollableAreas.push([child]);\n }\n }\n });\n\n return scrollableAreas;\n }, [props.children]);\n\n return (\n <Treeview\n {...props}\n className={cn('flex flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto', props.className)}\n ref={ref}>\n {scrollableAreas.map((area, i) =>\n Array.isArray(area) ? (\n <div\n className=\"flex h-0 flex-auto flex-shrink-0 flex-grow flex-col divide-y-2 divide-gray-100 overflow-y-auto\"\n key={i}>\n {area}\n </div>\n ) : (\n area\n )\n )}\n </Treeview>\n );\n}) as ForwardedNavigationMenuWithStatics;\n\nMenu.Group = MenuGroup;\n\n// Navigation\nexport type NavigationProps = React.HTMLAttributes<HTMLDivElement>;\n\nexport type ForwardedNavigationWithStatics = React.ForwardRefExoticComponent<\n NavigationProps & React.RefAttributes<HTMLDivElement>\n> & {\n /** Navigation link */\n Item: React.ForwardRefExoticComponent<NavigationItemProps & React.RefAttributes<HTMLAnchorElement>>;\n /**\n * Container for the expandable groups that hold navigation links.\n * Should be used as a direct child of Navigation component, e.g. `Navigation.Menu`.\n * Should have the menu groups as a direct child, e.g. `Navigation.Menu.Group`\n */\n Menu: ForwardedNavigationMenuWithStatics;\n /**\n * Isolated container within the Navigation.\n * This can be used to create a region in the Navigation that is usually not scrollable, nor expandable,\n * containing useful information for user and quick actions\n */\n Panel: React.ForwardRefExoticComponent<NavigationPanelProps & React.RefAttributes<HTMLDivElement>>;\n};\n\nexport const Navigation = React.forwardRef(function Navigation(props: NavigationProps, ref: React.Ref<HTMLDivElement>) {\n const { children, ...otherProps } = props;\n const className = cn('h-full flex flex-col bg-gray-100 divide-y-2 divide-gray-100', props.className);\n\n return (\n <div {...otherProps} className={className} data-taco=\"navigation\" ref={ref}>\n {children}\n </div>\n );\n}) as ForwardedNavigationWithStatics;\n\nNavigation.Menu = Menu;\nNavigation.Item = Item;\nNavigation.Panel = Panel;\n"],"names":["React","Item","Panel","MenuGroup","className","Menu","scrollableAreas","Navigation"],"mappings":";;;;;;;AAgCA,MAAM,OAAOA,eAAM,WAAW,SAASC,MAAK,OAA4B,KAAmC;AACjG,QAAA,EAAE,QAAQ,UAAU,QAAQ,SAAS,QAAQ,MAAM,GAAG,WAAA,IAAe;AACrE,QAAA,WAAW,aAAgC,GAAG;AACpD,QAAM,CAAC,eAAe,eAA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