@plexui/ui 0.22.0 → 0.24.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/es/components/Field/Field.js +2 -2
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/Page/Page.js +67 -0
- package/dist/es/components/Page/Page.js.map +1 -0
- package/dist/es/components/Page/index.js +2 -0
- package/dist/es/components/Page/index.js.map +1 -0
- package/dist/es/components/Select/Select.js +14 -6
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +17 -5
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Sidebar/index.js.map +1 -1
- package/dist/es/components/Sidebar/useSidebarContext.js +7 -3
- package/dist/es/components/Sidebar/useSidebarContext.js.map +1 -1
- package/dist/types/components/Field/Field.d.ts +7 -1
- package/dist/types/components/Page/Page.d.ts +82 -0
- package/dist/types/components/Page/index.d.ts +1 -0
- package/dist/types/components/Select/Select.d.ts +2 -2
- package/dist/types/components/Sidebar/Sidebar.d.ts +2 -2
- package/dist/types/components/Sidebar/index.d.ts +1 -1
- package/dist/types/components/Sidebar/useSidebarContext.d.ts +8 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { cloneElement, isValidElement, useId } from "react";
|
|
|
5
5
|
import { FieldError } from "../FieldError/index.js";
|
|
6
6
|
import s from "@plexui/styles/components/Field/Field.module.css";
|
|
7
7
|
const CONTROL_SIZES = new Set(["3xs", "2xs", "xs", "sm", "md", "lg", "xl", "2xl", "3xl"]);
|
|
8
|
-
export function Field({ label, description, errorMessage, labelAction, size: sizeProp, required = false, orientation: orientationProp, row = false, opticallyAlign, id: idProp, className, children, ...rest }) {
|
|
8
|
+
export function Field({ label, description, errorMessage, labelAction, size: sizeProp, required = false, orientation: orientationProp, row = false, fill = false, opticallyAlign, id: idProp, className, children, ...rest }) {
|
|
9
9
|
const orientation = orientationProp ?? (row ? "horizontal" : "vertical");
|
|
10
10
|
const generatedId = useId();
|
|
11
11
|
const fieldId = idProp || `field-${generatedId}`;
|
|
@@ -49,6 +49,6 @@ export function Field({ label, description, errorMessage, labelAction, size: siz
|
|
|
49
49
|
resolvedChildren = children;
|
|
50
50
|
}
|
|
51
51
|
const labelElement = (_jsxs("label", { className: s.Label, id: labelId, htmlFor: controlId, children: [label, required && (_jsx("span", { className: s.RequiredIndicator, "aria-hidden": "true", children: "*" }))] }));
|
|
52
|
-
return (_jsxs("div", { ...(row ? rest : undefined), className: clsx(s.Field, className), "data-size": size, "data-orientation": orientation, "data-optically-align": opticallyAlign, "data-row": row ? "" : undefined, children: [_jsxs("div", { className: s.LabelGroup, children: [labelAction ? (_jsxs("div", { className: s.LabelRow, children: [labelElement, _jsx("div", { className: s.LabelAction, children: labelAction })] })) : (labelElement), description && (_jsx("div", { className: s.Description, id: descriptionId, children: description }))] }), _jsxs("div", { className: s.Content, children: [_jsx("div", { className: s.Control, children: resolvedChildren }), errorMessage && (_jsx(FieldError, { id: errorId, children: errorMessage }))] })] }));
|
|
52
|
+
return (_jsxs("div", { ...(row ? rest : undefined), className: clsx(s.Field, className), "data-size": size, "data-orientation": orientation, "data-optically-align": opticallyAlign, "data-row": row ? "" : undefined, "data-fill": fill ? "" : undefined, children: [_jsxs("div", { className: s.LabelGroup, children: [labelAction ? (_jsxs("div", { className: s.LabelRow, children: [labelElement, _jsx("div", { className: s.LabelAction, children: labelAction })] })) : (labelElement), description && (_jsx("div", { className: s.Description, id: descriptionId, children: description }))] }), _jsxs("div", { className: s.Content, children: [_jsx("div", { className: s.Control, children: resolvedChildren }), errorMessage && (_jsx(FieldError, { id: errorId, children: errorMessage }))] })] }));
|
|
53
53
|
}
|
|
54
54
|
//# sourceMappingURL=Field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../../../src/components/Field/Field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,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AAC,CAAC,OAAO,aACvB,cAAK,SAAS,EAAE,CAAC,CAAC,OAAO,YAAG,gBAAgB,GAAO,EAClD,YAAY,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,YAAG,YAAY,GAAc,CACrD,IACG,IACF,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { cloneElement, isValidElement, useId } from \"react\"\n\nimport type { ControlSize } from \"../../types\"\nimport { FieldError } from \"../FieldError\"\n\nimport s from \"@plexui/styles/components/Field/Field.module.css\"\n\nexport type FieldChildProps = {\n id: string\n /** The label's id. Spread onto a control that the label's `for` cannot name, such as a Select trigger. */\n \"aria-labelledby\"?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n opticallyAlign?: \"start\" | \"end\"\n}\n\nconst CONTROL_SIZES: ReadonlySet<unknown> = new Set([\"3xs\", \"2xs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\", \"3xl\"])\n\nexport type FieldProps = {\n /**\n * Label text for the field\n */\n label: React.ReactNode\n /**\n * Helper/description text displayed below the label.\n * Automatically linked via aria-describedby.\n */\n description?: React.ReactNode\n /**\n * Error message displayed below the control.\n * When provided, the child control receives aria-invalid=\"true\".\n * Uses the existing FieldError component internally.\n */\n errorMessage?: React.ReactNode\n /**\n * Content placed at the end of the label row, such as a link that acts on\n * the field (\"Forgot password?\", \"Replace\").\n */\n labelAction?: React.ReactNode\n /**\n * Controls the font size of the label to visually match the child control's size.\n * Matches the ControlSize scale used by Input, Select, etc.\n * @default the child control's `size`, else \"md\"\n */\n size?: ControlSize\n /**\n * Display a required indicator (asterisk) after the label.\n * This is purely visual — it does not add the `required` HTML attribute.\n * @default false\n */\n required?: boolean\n /**\n * Layout direction of label and control.\n * - \"vertical\": label stacked above control (default)\n * - \"horizontal\": label beside control\n * @default \"horizontal\" on a `row`, else \"vertical\"\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * One line of a FieldGroup: label at the start, control at the end, an error\n * under both. Other div props reach the root only on a row, so it can carry\n * a click or data attributes.\n * @default false\n */\n row?: boolean\n /**\n * Allows overriding the auto-generated `id`. When provided, this becomes\n * the id set on the child control and the `htmlFor` on the label. A child's\n * own `id` wins over both: it stays, and the label's `htmlFor` follows it.\n */\n id?: string\n /**\n * Applies a negative margin on the child control using its gutter to\n * optically align the control's text with surrounding content.\n * Passed through to the child control via cloneElement / render prop.\n */\n opticallyAlign?: \"start\" | \"end\"\n /**\n * CSS class applied to the root wrapper\n */\n className?: string\n /**\n * The form control(s) to render.\n * - If a single ReactElement, Field clones it with { id, aria-describedby, aria-invalid },\n * keeping an `id` the child already has.\n * A child without its own `aria-label`, `aria-labelledby` or `label` also gets\n * `aria-labelledby` pointing at the label, which names controls the label's\n * `for` cannot reach, such as the Select and DatePicker triggers.\n * - If a function (render prop), it is called with { id, \"aria-labelledby\", \"aria-describedby\", \"aria-invalid\" }.\n */\n children: React.ReactElement | ((fieldProps: FieldChildProps) => React.ReactNode)\n} & Omit<React.ComponentProps<\"div\">, \"children\" | \"id\" | \"className\">\n\nexport function Field({\n label,\n description,\n errorMessage,\n labelAction,\n size: sizeProp,\n required = false,\n orientation: orientationProp,\n row = false,\n opticallyAlign,\n id: idProp,\n className,\n children,\n ...rest\n}: FieldProps) {\n const orientation = orientationProp ?? (row ? \"horizontal\" : \"vertical\")\n const generatedId = useId()\n const fieldId = idProp || `field-${generatedId}`\n const labelId = `${fieldId}-label`\n const childProps = isValidElement<{ size?: unknown; id?: string }>(children) ? children.props : undefined\n const childSize = childProps?.size\n const size = sizeProp ?? (CONTROL_SIZES.has(childSize) ? (childSize as ControlSize) : \"md\")\n // The control's id, which the label's `htmlFor` has to match\n const controlId = childProps?.id || fieldId\n const descriptionId = description ? `${fieldId}-description` : undefined\n const errorId = errorMessage ? `${fieldId}-error` : undefined\n\n // Build aria-describedby from description + error IDs\n const ariaDescribedBy =\n [descriptionId, errorId].filter(Boolean).join(\" \") || undefined\n\n const invalid = !!errorMessage\n\n // Props to inject into the child control (`aria-labelledby` is added below:\n // to a render prop's props, and to a cloned child without a name of its own)\n const fieldChildProps: FieldChildProps = {\n id: controlId,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": invalid || undefined,\n ...(opticallyAlign && { opticallyAlign }),\n }\n\n // Resolve the children\n let resolvedChildren: React.ReactNode\n if (typeof children === \"function\") {\n resolvedChildren = children({ ...fieldChildProps, \"aria-labelledby\": labelId })\n } else if (isValidElement(children)) {\n const child = children as React.ReactElement<Record<string, unknown>>\n // Merge with the child's own associations instead of overwriting them\n const childDescribedBy = child.props[\"aria-describedby\"] as string | undefined\n const childNamed =\n child.props[\"aria-label\"] != null || child.props[\"aria-labelledby\"] != null || child.props.label != null\n resolvedChildren = cloneElement(child, {\n ...fieldChildProps,\n \"aria-describedby\":\n [childDescribedBy, ariaDescribedBy].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": child.props[\"aria-invalid\"] ?? fieldChildProps[\"aria-invalid\"],\n ...(!childNamed && { \"aria-labelledby\": labelId }),\n })\n } else {\n resolvedChildren = children\n }\n\n const labelElement = (\n <label className={s.Label} id={labelId} htmlFor={controlId}>\n {label}\n {required && (\n <span className={s.RequiredIndicator} aria-hidden=\"true\">\n *\n </span>\n )}\n </label>\n )\n\n return (\n <div\n {...(row ? rest : undefined)}\n className={clsx(s.Field, className)}\n data-size={size}\n data-orientation={orientation}\n data-optically-align={opticallyAlign}\n data-row={row ? \"\" : undefined}\n >\n <div className={s.LabelGroup}>\n {labelAction ? (\n <div className={s.LabelRow}>\n {labelElement}\n <div className={s.LabelAction}>{labelAction}</div>\n </div>\n ) : (\n labelElement\n )}\n {description && (\n <div className={s.Description} id={descriptionId}>\n {description}\n </div>\n )}\n </div>\n <div className={s.Content}>\n <div className={s.Control}>{resolvedChildren}</div>\n {errorMessage && (\n <FieldError id={errorId}>{errorMessage}</FieldError>\n )}\n </div>\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,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IAC9C,CACP,CAAC,CAAC,CAAC,CACF,YAAY,CACb,EACA,WAAW,IAAI,CACd,cAAK,SAAS,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,EAAE,aAAa,YAC7C,WAAW,GACR,CACP,IACG,EACN,eAAK,SAAS,EAAE,CAAC,CAAC,OAAO,aACvB,cAAK,SAAS,EAAE,CAAC,CAAC,OAAO,YAAG,gBAAgB,GAAO,EAClD,YAAY,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,YAAG,YAAY,GAAc,CACrD,IACG,IACF,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { cloneElement, isValidElement, useId } from \"react\"\n\nimport type { ControlSize } from \"../../types\"\nimport { FieldError } from \"../FieldError\"\n\nimport s from \"@plexui/styles/components/Field/Field.module.css\"\n\nexport type FieldChildProps = {\n id: string\n /** The label's id. Spread onto a control that the label's `for` cannot name, such as a Select trigger. */\n \"aria-labelledby\"?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n opticallyAlign?: \"start\" | \"end\"\n}\n\nconst CONTROL_SIZES: ReadonlySet<unknown> = new Set([\"3xs\", \"2xs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\", \"3xl\"])\n\nexport type FieldProps = {\n /**\n * Label text for the field\n */\n label: React.ReactNode\n /**\n * Helper/description text displayed below the label.\n * Automatically linked via aria-describedby.\n */\n description?: React.ReactNode\n /**\n * Error message displayed below the control.\n * When provided, the child control receives aria-invalid=\"true\".\n * Uses the existing FieldError component internally.\n */\n errorMessage?: React.ReactNode\n /**\n * Content placed at the end of the label row, such as a link that acts on\n * the field (\"Forgot password?\", \"Replace\").\n */\n labelAction?: React.ReactNode\n /**\n * Controls the font size of the label to visually match the child control's size.\n * Matches the ControlSize scale used by Input, Select, etc.\n * @default the child control's `size`, else \"md\"\n */\n size?: ControlSize\n /**\n * Display a required indicator (asterisk) after the label.\n * This is purely visual — it does not add the `required` HTML attribute.\n * @default false\n */\n required?: boolean\n /**\n * Layout direction of label and control.\n * - \"vertical\": label stacked above control (default)\n * - \"horizontal\": label beside control\n * @default \"horizontal\" on a `row`, else \"vertical\"\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * One line of a FieldGroup: label at the start, control at the end, an error\n * under both. Other div props reach the root only on a row, so it can carry\n * a click or data attributes.\n * @default false\n */\n row?: boolean\n /**\n * On a `row`, the control takes the rest of the line after the label, for a\n * list of tags and the like.\n * @default false\n */\n fill?: boolean\n /**\n * Allows overriding the auto-generated `id`. When provided, this becomes\n * the id set on the child control and the `htmlFor` on the label. A child's\n * own `id` wins over both: it stays, and the label's `htmlFor` follows it.\n */\n id?: string\n /**\n * Applies a negative margin on the child control using its gutter to\n * optically align the control's text with surrounding content.\n * Passed through to the child control via cloneElement / render prop.\n */\n opticallyAlign?: \"start\" | \"end\"\n /**\n * CSS class applied to the root wrapper\n */\n className?: string\n /**\n * The form control(s) to render.\n * - If a single ReactElement, Field clones it with { id, aria-describedby, aria-invalid },\n * keeping an `id` the child already has.\n * A child without its own `aria-label`, `aria-labelledby` or `label` also gets\n * `aria-labelledby` pointing at the label, which names controls the label's\n * `for` cannot reach, such as the Select and DatePicker triggers.\n * - If a function (render prop), it is called with { id, \"aria-labelledby\", \"aria-describedby\", \"aria-invalid\" }.\n */\n children: React.ReactElement | ((fieldProps: FieldChildProps) => React.ReactNode)\n} & Omit<React.ComponentProps<\"div\">, \"children\" | \"id\" | \"className\">\n\nexport function Field({\n label,\n description,\n errorMessage,\n labelAction,\n size: sizeProp,\n required = false,\n orientation: orientationProp,\n row = false,\n fill = false,\n opticallyAlign,\n id: idProp,\n className,\n children,\n ...rest\n}: FieldProps) {\n const orientation = orientationProp ?? (row ? \"horizontal\" : \"vertical\")\n const generatedId = useId()\n const fieldId = idProp || `field-${generatedId}`\n const labelId = `${fieldId}-label`\n const childProps = isValidElement<{ size?: unknown; id?: string }>(children) ? children.props : undefined\n const childSize = childProps?.size\n const size = sizeProp ?? (CONTROL_SIZES.has(childSize) ? (childSize as ControlSize) : \"md\")\n // The control's id, which the label's `htmlFor` has to match\n const controlId = childProps?.id || fieldId\n const descriptionId = description ? `${fieldId}-description` : undefined\n const errorId = errorMessage ? `${fieldId}-error` : undefined\n\n // Build aria-describedby from description + error IDs\n const ariaDescribedBy =\n [descriptionId, errorId].filter(Boolean).join(\" \") || undefined\n\n const invalid = !!errorMessage\n\n // Props to inject into the child control (`aria-labelledby` is added below:\n // to a render prop's props, and to a cloned child without a name of its own)\n const fieldChildProps: FieldChildProps = {\n id: controlId,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": invalid || undefined,\n ...(opticallyAlign && { opticallyAlign }),\n }\n\n // Resolve the children\n let resolvedChildren: React.ReactNode\n if (typeof children === \"function\") {\n resolvedChildren = children({ ...fieldChildProps, \"aria-labelledby\": labelId })\n } else if (isValidElement(children)) {\n const child = children as React.ReactElement<Record<string, unknown>>\n // Merge with the child's own associations instead of overwriting them\n const childDescribedBy = child.props[\"aria-describedby\"] as string | undefined\n const childNamed =\n child.props[\"aria-label\"] != null || child.props[\"aria-labelledby\"] != null || child.props.label != null\n resolvedChildren = cloneElement(child, {\n ...fieldChildProps,\n \"aria-describedby\":\n [childDescribedBy, ariaDescribedBy].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": child.props[\"aria-invalid\"] ?? fieldChildProps[\"aria-invalid\"],\n ...(!childNamed && { \"aria-labelledby\": labelId }),\n })\n } else {\n resolvedChildren = children\n }\n\n const labelElement = (\n <label className={s.Label} id={labelId} htmlFor={controlId}>\n {label}\n {required && (\n <span className={s.RequiredIndicator} aria-hidden=\"true\">\n *\n </span>\n )}\n </label>\n )\n\n return (\n <div\n {...(row ? rest : undefined)}\n className={clsx(s.Field, className)}\n data-size={size}\n data-orientation={orientation}\n data-optically-align={opticallyAlign}\n data-row={row ? \"\" : undefined}\n data-fill={fill ? \"\" : undefined}\n >\n <div className={s.LabelGroup}>\n {labelAction ? (\n <div className={s.LabelRow}>\n {labelElement}\n <div className={s.LabelAction}>{labelAction}</div>\n </div>\n ) : (\n labelElement\n )}\n {description && (\n <div className={s.Description} id={descriptionId}>\n {description}\n </div>\n )}\n </div>\n <div className={s.Content}>\n <div className={s.Control}>{resolvedChildren}</div>\n {errorMessage && (\n <FieldError id={errorId}>{errorMessage}</FieldError>\n )}\n </div>\n </div>\n )\n}\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { createContext, useContext, useMemo, useState, } from "react";
|
|
5
|
+
import s from "@plexui/styles/components/Page/Page.module.css";
|
|
6
|
+
// A trackpad's small settle at the top must not flash the line.
|
|
7
|
+
const SCROLLED_AFTER = 4;
|
|
8
|
+
const PageContext = createContext(null);
|
|
9
|
+
function usePageContext(part) {
|
|
10
|
+
const context = useContext(PageContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error(`Page.${part} must be used within Page`);
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
function PageRoot({ width = "full", className, children, ...restProps }) {
|
|
17
|
+
const [scrolled, setScrolled] = useState(false);
|
|
18
|
+
const context = useMemo(() => ({ scrolled, setScrolled }), [scrolled]);
|
|
19
|
+
return (_jsx(PageContext.Provider, { value: context, children: _jsx("div", { className: clsx(s.Page, className), "data-width": width, ...restProps, children: children }) }));
|
|
20
|
+
}
|
|
21
|
+
PageRoot.displayName = "Page";
|
|
22
|
+
function PageHeader({ divider = true, className, children, ...restProps }) {
|
|
23
|
+
const { scrolled } = usePageContext("Header");
|
|
24
|
+
return (_jsx("div", { className: clsx(s.Header, className), "data-scrolled": divider && scrolled ? "" : undefined, ...restProps, children: _jsx("div", { className: s.Head, children: children }) }));
|
|
25
|
+
}
|
|
26
|
+
PageHeader.displayName = "Page.Header";
|
|
27
|
+
function PageBar({ className, ...restProps }) {
|
|
28
|
+
return _jsx("div", { className: clsx(s.Bar, className), ...restProps });
|
|
29
|
+
}
|
|
30
|
+
PageBar.displayName = "Page.Bar";
|
|
31
|
+
function PageHeading({ className, ...restProps }) {
|
|
32
|
+
return _jsx("div", { className: clsx(s.Heading, className), ...restProps });
|
|
33
|
+
}
|
|
34
|
+
PageHeading.displayName = "Page.Heading";
|
|
35
|
+
function PageTitle({ className, ...restProps }) {
|
|
36
|
+
return _jsx("h1", { className: clsx(s.Title, className), ...restProps });
|
|
37
|
+
}
|
|
38
|
+
PageTitle.displayName = "Page.Title";
|
|
39
|
+
function PageSubtitle({ className, ...restProps }) {
|
|
40
|
+
return _jsx("p", { className: clsx(s.Subtitle, className), ...restProps });
|
|
41
|
+
}
|
|
42
|
+
PageSubtitle.displayName = "Page.Subtitle";
|
|
43
|
+
function PageActions({ className, ...restProps }) {
|
|
44
|
+
return _jsx("div", { className: clsx(s.Actions, className), ...restProps });
|
|
45
|
+
}
|
|
46
|
+
PageActions.displayName = "Page.Actions";
|
|
47
|
+
function PageContent({ fill = false, className, children, onScroll, ...restProps }) {
|
|
48
|
+
const { setScrolled } = usePageContext("Content");
|
|
49
|
+
const handleScroll = (event) => {
|
|
50
|
+
setScrolled(event.currentTarget.scrollTop > SCROLLED_AFTER);
|
|
51
|
+
onScroll?.(event);
|
|
52
|
+
};
|
|
53
|
+
return (_jsx("div", { className: clsx(s.Content, className), "data-fill": fill ? "" : undefined, onScroll: handleScroll, ...restProps, children: _jsx("div", { className: s.Column, children: children }) }));
|
|
54
|
+
}
|
|
55
|
+
PageContent.displayName = "Page.Content";
|
|
56
|
+
/* ------------------------------------------------------------------ */
|
|
57
|
+
/* Compound */
|
|
58
|
+
/* ------------------------------------------------------------------ */
|
|
59
|
+
export const Page = PageRoot;
|
|
60
|
+
Page.Header = PageHeader;
|
|
61
|
+
Page.Bar = PageBar;
|
|
62
|
+
Page.Heading = PageHeading;
|
|
63
|
+
Page.Title = PageTitle;
|
|
64
|
+
Page.Subtitle = PageSubtitle;
|
|
65
|
+
Page.Actions = PageActions;
|
|
66
|
+
Page.Content = PageContent;
|
|
67
|
+
//# sourceMappingURL=Page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Page.js","sourceRoot":"","sources":["../../../../src/components/Page/Page.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EACL,aAAa,EACb,UAAU,EACV,OAAO,EACP,QAAQ,GAIT,MAAM,OAAO,CAAA;AACd,OAAO,CAAC,MAAM,gDAAgD,CAAA;AAI9D,gEAAgE;AAChE,MAAM,cAAc,GAAG,CAAC,CAAA;AAOxB,MAAM,WAAW,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAA;AAEhE,SAAS,cAAc,CAAC,IAAY;IAClC,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAA;IACvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,2BAA2B,CAAC,CAAA;IAC1D,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAoBD,SAAS,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAa;IAChF,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEtE,OAAO,CACL,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAClC,cAAK,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,gBAAc,KAAK,KAAM,SAAS,YACtE,QAAQ,GACL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GAAG,OAAO,CAAA;AAClB,IAAI,CAAC,OAAO,GAAG,WAAW,CAAA;AAC1B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;AACtB,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAA;AAC5B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAA;AAC1B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport {\n createContext,\n useContext,\n useMemo,\n useState,\n type HTMLAttributes,\n type Ref,\n type UIEvent,\n} from \"react\"\nimport s from \"@plexui/styles/components/Page/Page.module.css\"\n\nexport type PageWidth = \"full\" | \"wide\" | \"column\"\n\n// A trackpad's small settle at the top must not flash the line.\nconst SCROLLED_AFTER = 4\n\ntype PageContextValue = {\n scrolled: boolean\n setScrolled: (scrolled: boolean) => void\n}\n\nconst PageContext = createContext<PageContextValue | null>(null)\n\nfunction usePageContext(part: string): PageContextValue {\n const context = useContext(PageContext)\n if (!context) {\n throw new Error(`Page.${part} must be used within Page`)\n }\n return context\n}\n\n/* ------------------------------------------------------------------ */\n/* Root */\n/* ------------------------------------------------------------------ */\n\nexport type PageProps = HTMLAttributes<HTMLDivElement> & {\n /**\n * Width of the column that header and content share.\n * - `\"full\"` — edge to edge, for tables (default)\n * - `\"wide\"` — 1280px, centred, for overviews\n * - `\"column\"` — 768px, centred, for settings and forms\n *\n * Set `--page-width` on the page for any other width.\n * @default \"full\"\n */\n width?: PageWidth\n ref?: Ref<HTMLDivElement>\n}\n\nfunction PageRoot({ width = \"full\", className, children, ...restProps }: PageProps) {\n const [scrolled, setScrolled] = useState(false)\n const context = useMemo(() => ({ scrolled, setScrolled }), [scrolled])\n\n return (\n <PageContext.Provider value={context}>\n <div className={clsx(s.Page, className)} data-width={width} {...restProps}>\n {children}\n </div>\n </PageContext.Provider>\n )\n}\nPageRoot.displayName = \"Page\"\n\n/* ------------------------------------------------------------------ */\n/* Header */\n/* ------------------------------------------------------------------ */\n\nexport type PageHeaderProps = HTMLAttributes<HTMLDivElement> & {\n /**\n * Shows the line, and the glass on a phone, once the content has scrolled under the header.\n * Turn it off when the content already draws a line of its own at that place.\n * @default true\n */\n divider?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nfunction PageHeader({ divider = true, className, children, ...restProps }: PageHeaderProps) {\n const { scrolled } = usePageContext(\"Header\")\n\n return (\n <div\n className={clsx(s.Header, className)}\n data-scrolled={divider && scrolled ? \"\" : undefined}\n {...restProps}\n >\n <div className={s.Head}>{children}</div>\n </div>\n )\n}\nPageHeader.displayName = \"Page.Header\"\n\n/* ------------------------------------------------------------------ */\n/* Slots */\n/* ------------------------------------------------------------------ */\n\nexport type PageSlotProps = HTMLAttributes<HTMLDivElement> & { ref?: Ref<HTMLDivElement> }\n\nfunction PageBar({ className, ...restProps }: PageSlotProps) {\n return <div className={clsx(s.Bar, className)} {...restProps} />\n}\nPageBar.displayName = \"Page.Bar\"\n\nfunction PageHeading({ className, ...restProps }: PageSlotProps) {\n return <div className={clsx(s.Heading, className)} {...restProps} />\n}\nPageHeading.displayName = \"Page.Heading\"\n\nfunction PageTitle({\n className,\n ...restProps\n}: HTMLAttributes<HTMLHeadingElement> & { ref?: Ref<HTMLHeadingElement> }) {\n return <h1 className={clsx(s.Title, className)} {...restProps} />\n}\nPageTitle.displayName = \"Page.Title\"\n\nfunction PageSubtitle({\n className,\n ...restProps\n}: HTMLAttributes<HTMLParagraphElement> & { ref?: Ref<HTMLParagraphElement> }) {\n return <p className={clsx(s.Subtitle, className)} {...restProps} />\n}\nPageSubtitle.displayName = \"Page.Subtitle\"\n\nfunction PageActions({ className, ...restProps }: PageSlotProps) {\n return <div className={clsx(s.Actions, className)} {...restProps} />\n}\nPageActions.displayName = \"Page.Actions\"\n\n/* ------------------------------------------------------------------ */\n/* Content */\n/* ------------------------------------------------------------------ */\n\nexport type PageContentProps = HTMLAttributes<HTMLDivElement> & {\n /**\n * The content fills the page and scrolls inside itself, as a table does: the page stops\n * scrolling from 768px up.\n * @default false\n */\n fill?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nfunction PageContent({ fill = false, className, children, onScroll, ...restProps }: PageContentProps) {\n const { setScrolled } = usePageContext(\"Content\")\n\n const handleScroll = (event: UIEvent<HTMLDivElement>) => {\n setScrolled(event.currentTarget.scrollTop > SCROLLED_AFTER)\n onScroll?.(event)\n }\n\n return (\n <div\n className={clsx(s.Content, className)}\n data-fill={fill ? \"\" : undefined}\n onScroll={handleScroll}\n {...restProps}\n >\n <div className={s.Column}>{children}</div>\n </div>\n )\n}\nPageContent.displayName = \"Page.Content\"\n\n/* ------------------------------------------------------------------ */\n/* Compound */\n/* ------------------------------------------------------------------ */\n\nexport const Page = PageRoot as typeof PageRoot & {\n Header: typeof PageHeader\n Bar: typeof PageBar\n Heading: typeof PageHeading\n Title: typeof PageTitle\n Subtitle: typeof PageSubtitle\n Actions: typeof PageActions\n Content: typeof PageContent\n}\nPage.Header = PageHeader\nPage.Bar = PageBar\nPage.Heading = PageHeading\nPage.Title = PageTitle\nPage.Subtitle = PageSubtitle\nPage.Actions = PageActions\nPage.Content = PageContent\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Page/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,GAML,MAAM,QAAQ,CAAA","sourcesContent":["export {\n Page,\n type PageContentProps,\n type PageHeaderProps,\n type PageProps,\n type PageSlotProps,\n type PageWidth,\n} from \"./Page\"\n"]}
|
|
@@ -36,7 +36,7 @@ const DefaultMultiTriggerView = ({ values, selectedAll, }) => {
|
|
|
36
36
|
return _jsx(_Fragment, { children: displayValue });
|
|
37
37
|
};
|
|
38
38
|
export const Select = (props) => {
|
|
39
|
-
const { id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, required, value, name, multiple, variant = "outline", size = "md", dropdownIconType = "dropdown", loading = false, clearable = false, disabled = false, placeholder = "Select...", loadingPlaceholder = "Loading...", allSelectedLabel = "All selected", pill = false,
|
|
39
|
+
const { id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, required, value, name, multiple, variant = "outline", size = "md", dropdownIconType = "dropdown", loading = false, clearable = false, disabled = false, placeholder = "Select...", loadingPlaceholder = "Loading...", allSelectedLabel = "All selected", pill = false, listMinWidth, options, actions: propActions = [], side = "bottom", avoidCollisions = true, onChange, optionClassName, OptionView = DefaultOptionView, TriggerStartIcon, triggerClassName, opticallyAlign, TriggerView: TriggerViewFromProps, searchPlaceholder = "", searchAriaLabel = "Search options", searchSize, searchPredicate = defaultSearchPredicate, searchEmptyMessage = "No results found.", trigger, checkPosition = 'start', } = props;
|
|
40
40
|
// Block default is dynamic, based on `variant`
|
|
41
41
|
const block = props.block ?? variant !== "ghost";
|
|
42
42
|
// Align default is dynamic, based on `block`
|
|
@@ -45,10 +45,6 @@ export const Select = (props) => {
|
|
|
45
45
|
// "start"/"end" tried to line the option labels up with the trigger's text and
|
|
46
46
|
// instead left the menu hanging past the field it belongs to.
|
|
47
47
|
const alignOffset = props.alignOffset ?? 0;
|
|
48
|
-
// A menu is never narrower than the field it belongs to, so `listWidth="auto"`
|
|
49
|
-
// grows with the content but does not shrink below the trigger (the CSS
|
|
50
|
-
// fallback reads the trigger width). Inline selects keep their 300px floor.
|
|
51
|
-
const listMinWidth = props.listMinWidth ?? (block ? undefined : 300);
|
|
52
48
|
// Create stable, mutable references to avoid memoization requirements from consumers
|
|
53
49
|
const onSelectRef = useLatestValue((selectedOption, removeOption) => {
|
|
54
50
|
if (multiple) {
|
|
@@ -93,6 +89,11 @@ export const Select = (props) => {
|
|
|
93
89
|
const triggerId = `select-trigger-${internalTriggerId}`;
|
|
94
90
|
// Locking down searchable count to a single value. Could make this customizable in the future, but would want guardrails.
|
|
95
91
|
const searchable = optionsCount > 15;
|
|
92
|
+
// A block menu matches its field. An inline one fits its options: no narrower than
|
|
93
|
+
// its trigger (the CSS fallback reads the trigger width), no wider than 300px.
|
|
94
|
+
const fitsOptions = !block && props.listWidth === undefined;
|
|
95
|
+
const listWidth = props.listWidth ?? (fitsOptions ? "auto" : undefined);
|
|
96
|
+
const listMaxWidth = props.listMaxWidth ?? (fitsOptions ? 300 : "auto");
|
|
96
97
|
// Narrow known values for context
|
|
97
98
|
const dynamicContextProps = useMemo(() => {
|
|
98
99
|
if (multiple) {
|
|
@@ -337,7 +338,7 @@ const useCustomSelectMenuContext = () => {
|
|
|
337
338
|
return context;
|
|
338
339
|
};
|
|
339
340
|
const CustomSelectMenu = ({ onOpenChange }) => {
|
|
340
|
-
const { multiple, value, options, searchable, searchPredicateRef } = useSelectContext();
|
|
341
|
+
const { multiple, value, options, searchable, searchPredicateRef, listWidth } = useSelectContext();
|
|
341
342
|
const requestCloseRef = useRef(() => onOpenChange(false));
|
|
342
343
|
const menuRef = useRef(null);
|
|
343
344
|
const listRef = useRef(null);
|
|
@@ -518,6 +519,13 @@ const CustomSelectMenu = ({ onOpenChange }) => {
|
|
|
518
519
|
};
|
|
519
520
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- Intentionally an onMount effect
|
|
520
521
|
}, []);
|
|
522
|
+
// A long list has a search field: the menu keeps the width of all its options as the results narrow.
|
|
523
|
+
useLayoutEffect(() => {
|
|
524
|
+
if (searchable && listWidth === "auto" && menuRef.current) {
|
|
525
|
+
menuRef.current.style.minWidth = `${menuRef.current.offsetWidth}px`;
|
|
526
|
+
}
|
|
527
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- Intentionally an onMount effect
|
|
528
|
+
}, []);
|
|
521
529
|
// On search behavior
|
|
522
530
|
useLayoutEffect(() => {
|
|
523
531
|
// This effect will run on mount, but we want to skip it.
|