@betterinternship/components 3.2.2 → 3.2.3

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.
@@ -72,7 +72,7 @@ function FilterMenu(props) {
72
72
  return (jsxs(Fragment, { children: [trigger, jsx(Sheet, { open: open, onOpenChange: setOpen, children: jsxs(SheetContent, { side: "bottom", showCloseButton: false, overlayClassName: "z-[1090] bg-black/25 backdrop-blur-[1px]", "aria-describedby": undefined, onOpenAutoFocus: (event) => {
73
73
  event.preventDefault();
74
74
  closeRef.current?.focus();
75
- }, className: "flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]", children: [jsxs("div", { className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4", children: [jsx(SheetTitle, { className: "text-base font-semibold text-foreground", children: title }), jsx("button", { ref: closeRef, type: "button", "aria-label": "Close", className: "-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: () => setOpen(false), children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] }), jsx("div", { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-2", children: list }), jsxs("div", { className: "flex shrink-0 gap-2 border-t border-border px-4 pt-3", children: [clearInSheet && (jsx(Button, { type: "button", variant: "outline", className: "flex-1", onClick: clearInSheet, children: clearLabel })), jsx(Button, { type: "button", className: "flex-1", onClick: () => setOpen(false), children: "Done" })] })] }) })] }));
75
+ }, className: "flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]", children: [jsxs("div", { className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4", children: [jsx(SheetTitle, { className: "text-base font-semibold text-foreground", children: title }), jsx("button", { ref: closeRef, type: "button", "aria-label": "Close", className: "-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: () => setOpen(false), children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] }), jsx("div", { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-2", children: list }), jsxs("div", { className: "flex shrink-0 gap-2 border-t border-border px-4 pt-3", children: [clearInSheet && (jsx(Button, { type: "button", variant: "ghost", scheme: "neutral", className: "flex-1", onClick: clearInSheet, children: clearLabel })), jsx(Button, { type: "button", variant: "outline", className: "flex-1", onClick: () => setOpen(false), children: "Done" })] })] }) })] }));
76
76
  return (jsxs(Popover, { open: open, onOpenChange: setOpen, children: [jsx(PopoverTrigger, { asChild: true, children: trigger }), jsxs(PopoverContent, { align: align, className: cn("w-56 p-0", contentClassName), children: [list, onClear && (jsx("div", { className: "border-t border-border p-option-inset", children: jsx(Button, { type: "button", variant: "link", scheme: "primary", size: "xs", onClick: onClear, children: clearLabel }) }))] })] }));
77
77
  }
78
78
 
@@ -1 +1 @@
1
- {"version":3,"file":"option-list.js","sources":["../../src/components/option-list.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown, X } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { Button } from \"./button\";\nimport { Checkbox } from \"./checkbox\";\nimport { FilterChip } from \"./filter-chip\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\n\n/*\n * The shared look for every list of options (menus, selects, dropdowns,\n * autocomplete, filter menus): the list is inset from its container's edge,\n * and each row is its own rounded box with a little space between rows, so\n * hover and selection read as distinct pills rather than full-bleed stripes.\n */\n\n/** Padding + row gap for a list of options inside a popover or sheet. */\nexport const optionListClassName = \"flex flex-col gap-option-gap p-option-inset\";\n\n/** One option row. Pair with a hover/focus or selected state as needed. */\nexport const optionRowClassName =\n \"relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-foreground outline-none transition-colors duration-state hover:bg-muted focus-visible:bg-muted motion-reduce:transition-none max-md:min-h-11\";\n\nexport type CheckboxListItem = {\n label: React.ReactNode;\n checked: boolean;\n onCheckedChange: (checked: boolean) => void;\n /** Indents the row under a group heading row. */\n indent?: boolean;\n /** Bolder label, e.g. a group's \"All …\" row. */\n strong?: boolean;\n disabled?: boolean;\n};\n\n/** A list of checkbox rows in the shared option style. */\nexport function CheckboxList({\n items,\n className,\n \"aria-label\": label,\n}: {\n items: CheckboxListItem[];\n className?: string;\n \"aria-label\"?: string;\n}) {\n return (\n <ul\n aria-label={label}\n className={cn(\"m-0 list-none\", optionListClassName, className)}\n >\n {items.map((item, index) => (\n <li key={index}>\n <label\n className={cn(\n optionRowClassName,\n item.indent && \"pl-8\",\n item.strong && \"font-medium\",\n item.disabled && \"pointer-events-none opacity-50\",\n )}\n >\n <Checkbox\n checked={item.checked}\n disabled={item.disabled}\n onCheckedChange={(checked) =>\n item.onCheckedChange(checked === true)\n }\n />\n <span className=\"min-w-0 flex-1\">{item.label}</span>\n </label>\n </li>\n ))}\n </ul>\n );\n}\n\nexport type FilterMenuOption = { label: React.ReactNode; value: string };\n\ntype FilterMenuCommon = {\n /** The chip's label (and the sheet title when it's text). */\n label?: React.ReactNode;\n /** Replaces the default chip, e.g. a labelled field button. */\n trigger?: React.ReactElement<React.HTMLAttributes<HTMLElement>>;\n /** Sheet title / list name when `label` isn't plain text. */\n title?: string;\n /** Shows a clear action (popover footer and sheet footer). */\n onClear?: () => void;\n clearLabel?: string;\n size?: \"xs\" | \"sm\" | \"md\";\n align?: \"start\" | \"center\" | \"end\";\n className?: string;\n contentClassName?: string;\n};\n\n/** Simple filters: options in, selected values out. */\ntype FilterMenuOptionsProps = FilterMenuCommon & {\n options: FilterMenuOption[];\n /** The selected option values. */\n value: string[];\n onValueChange: (value: string[]) => void;\n items?: never;\n};\n\n/** Lists with their own rules (groups, indents): the rows themselves. */\ntype FilterMenuItemsProps = FilterMenuCommon & {\n items: CheckboxListItem[];\n options?: never;\n value?: never;\n onValueChange?: never;\n};\n\nexport type FilterMenuProps = FilterMenuOptionsProps | FilterMenuItemsProps;\n\n/**\n * A checklist behind a trigger: a dropdown on desktop and a bottom sheet\n * (with Clear and Done) on phones. Each tick applies immediately.\n *\n * Feed it either `options` + `value` + `onValueChange` (simple filters; the\n * default trigger is a FilterChip showing the count in the selected,\n * secondary style), or ready-made `items` with your own `trigger`.\n */\nexport function FilterMenu(props: FilterMenuProps) {\n const {\n label,\n trigger: customTrigger,\n title: titleProp,\n onClear,\n clearLabel = \"Clear\",\n size = \"sm\",\n align = \"start\",\n className,\n contentClassName,\n } = props;\n const isMobile = useMobile();\n const [open, setOpen] = React.useState(false);\n const closeRef = React.useRef<HTMLButtonElement>(null);\n\n // Both ways in become the same rows.\n const items: CheckboxListItem[] =\n props.items ??\n props.options.map((option) => ({\n label: option.label,\n checked: props.value.includes(option.value),\n onCheckedChange: (on) =>\n props.onValueChange(\n on\n ? [...props.value, option.value]\n : props.value.filter((item) => item !== option.value),\n ),\n }));\n const count = props.items\n ? props.items.filter((item) => item.checked).length\n : props.value.length;\n const title = titleProp ?? (typeof label === \"string\" ? label : \"Filter\");\n // The sheet always offers Clear while something's on; the popover only\n // when the caller asks for it.\n const clearInSheet =\n onClear ??\n (!props.items && count > 0 ? () => props.onValueChange([]) : undefined);\n\n const triggerProps = {\n \"aria-haspopup\": \"dialog\" as const,\n \"aria-expanded\": open,\n onClick: isMobile ? () => setOpen(true) : undefined,\n };\n const trigger = customTrigger ? (\n React.cloneElement(customTrigger, {\n ...triggerProps,\n onClick: (event: React.MouseEvent<HTMLElement>) => {\n customTrigger.props.onClick?.(event);\n triggerProps.onClick?.();\n },\n })\n ) : (\n <FilterChip\n size={size}\n selected={count > 0}\n count={count || undefined}\n className={className}\n {...triggerProps}\n >\n {label}\n <ChevronDown size={14} aria-hidden=\"true\" className=\"-mr-1\" />\n </FilterChip>\n );\n\n const list = <CheckboxList aria-label={title} items={items} />;\n\n // Phones: a bottom sheet, like Autocomplete and Select.\n if (isMobile)\n return (\n <>\n {trigger}\n <Sheet open={open} onOpenChange={setOpen}>\n <SheetContent\n side=\"bottom\"\n showCloseButton={false}\n overlayClassName=\"z-[1090] bg-black/25 backdrop-blur-[1px]\"\n aria-describedby={undefined}\n onOpenAutoFocus={(event) => {\n event.preventDefault();\n closeRef.current?.focus();\n }}\n className=\"flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]\"\n >\n <div className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">\n {title}\n </SheetTitle>\n <button\n ref={closeRef}\n type=\"button\"\n aria-label=\"Close\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onClick={() => setOpen(false)}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <div className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain px-2\">\n {list}\n </div>\n <div className=\"flex shrink-0 gap-2 border-t border-border px-4 pt-3\">\n {clearInSheet && (\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"flex-1\"\n onClick={clearInSheet}\n >\n {clearLabel}\n </Button>\n )}\n <Button\n type=\"button\"\n className=\"flex-1\"\n onClick={() => setOpen(false)}\n >\n Done\n </Button>\n </div>\n </SheetContent>\n </Sheet>\n </>\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>{trigger}</PopoverTrigger>\n <PopoverContent\n align={align}\n className={cn(\"w-56 p-0\", contentClassName)}\n >\n {list}\n {onClear && (\n <div className=\"border-t border-border p-option-inset\">\n <Button\n type=\"button\"\n variant=\"link\"\n scheme=\"primary\"\n size=\"xs\"\n onClick={onClear}\n >\n {clearLabel}\n </Button>\n </div>\n )}\n </PopoverContent>\n </Popover>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAaA;;;;;AAKG;AAEH;AACO;AAEP;AACO;AAcP;AACM;;AAqCN;AAuCA;;;;;;;AAOG;AACG;AACJ;AAWA;AACA;;;AAIA;;;;;;AASU;AAEP;AACH;AACE;AACA;AACF;;;;;AAOA;AACE;AACA;AACA;;AAEF;AAEI;AACA;;AAEE;;;;;AAmBN;AACE;;AAWU;;AA6CZ;AAwBF;;"}
1
+ {"version":3,"file":"option-list.js","sources":["../../src/components/option-list.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown, X } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { Button } from \"./button\";\nimport { Checkbox } from \"./checkbox\";\nimport { FilterChip } from \"./filter-chip\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\n\n/*\n * The shared look for every list of options (menus, selects, dropdowns,\n * autocomplete, filter menus): the list is inset from its container's edge,\n * and each row is its own rounded box with a little space between rows, so\n * hover and selection read as distinct pills rather than full-bleed stripes.\n */\n\n/** Padding + row gap for a list of options inside a popover or sheet. */\nexport const optionListClassName = \"flex flex-col gap-option-gap p-option-inset\";\n\n/** One option row. Pair with a hover/focus or selected state as needed. */\nexport const optionRowClassName =\n \"relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-foreground outline-none transition-colors duration-state hover:bg-muted focus-visible:bg-muted motion-reduce:transition-none max-md:min-h-11\";\n\nexport type CheckboxListItem = {\n label: React.ReactNode;\n checked: boolean;\n onCheckedChange: (checked: boolean) => void;\n /** Indents the row under a group heading row. */\n indent?: boolean;\n /** Bolder label, e.g. a group's \"All …\" row. */\n strong?: boolean;\n disabled?: boolean;\n};\n\n/** A list of checkbox rows in the shared option style. */\nexport function CheckboxList({\n items,\n className,\n \"aria-label\": label,\n}: {\n items: CheckboxListItem[];\n className?: string;\n \"aria-label\"?: string;\n}) {\n return (\n <ul\n aria-label={label}\n className={cn(\"m-0 list-none\", optionListClassName, className)}\n >\n {items.map((item, index) => (\n <li key={index}>\n <label\n className={cn(\n optionRowClassName,\n item.indent && \"pl-8\",\n item.strong && \"font-medium\",\n item.disabled && \"pointer-events-none opacity-50\",\n )}\n >\n <Checkbox\n checked={item.checked}\n disabled={item.disabled}\n onCheckedChange={(checked) =>\n item.onCheckedChange(checked === true)\n }\n />\n <span className=\"min-w-0 flex-1\">{item.label}</span>\n </label>\n </li>\n ))}\n </ul>\n );\n}\n\nexport type FilterMenuOption = { label: React.ReactNode; value: string };\n\ntype FilterMenuCommon = {\n /** The chip's label (and the sheet title when it's text). */\n label?: React.ReactNode;\n /** Replaces the default chip, e.g. a labelled field button. */\n trigger?: React.ReactElement<React.HTMLAttributes<HTMLElement>>;\n /** Sheet title / list name when `label` isn't plain text. */\n title?: string;\n /** Shows a clear action (popover footer and sheet footer). */\n onClear?: () => void;\n clearLabel?: string;\n size?: \"xs\" | \"sm\" | \"md\";\n align?: \"start\" | \"center\" | \"end\";\n className?: string;\n contentClassName?: string;\n};\n\n/** Simple filters: options in, selected values out. */\ntype FilterMenuOptionsProps = FilterMenuCommon & {\n options: FilterMenuOption[];\n /** The selected option values. */\n value: string[];\n onValueChange: (value: string[]) => void;\n items?: never;\n};\n\n/** Lists with their own rules (groups, indents): the rows themselves. */\ntype FilterMenuItemsProps = FilterMenuCommon & {\n items: CheckboxListItem[];\n options?: never;\n value?: never;\n onValueChange?: never;\n};\n\nexport type FilterMenuProps = FilterMenuOptionsProps | FilterMenuItemsProps;\n\n/**\n * A checklist behind a trigger: a dropdown on desktop and a bottom sheet\n * (with Clear and Done) on phones. Each tick applies immediately.\n *\n * Feed it either `options` + `value` + `onValueChange` (simple filters; the\n * default trigger is a FilterChip showing the count in the selected,\n * secondary style), or ready-made `items` with your own `trigger`.\n */\nexport function FilterMenu(props: FilterMenuProps) {\n const {\n label,\n trigger: customTrigger,\n title: titleProp,\n onClear,\n clearLabel = \"Clear\",\n size = \"sm\",\n align = \"start\",\n className,\n contentClassName,\n } = props;\n const isMobile = useMobile();\n const [open, setOpen] = React.useState(false);\n const closeRef = React.useRef<HTMLButtonElement>(null);\n\n // Both ways in become the same rows.\n const items: CheckboxListItem[] =\n props.items ??\n props.options.map((option) => ({\n label: option.label,\n checked: props.value.includes(option.value),\n onCheckedChange: (on) =>\n props.onValueChange(\n on\n ? [...props.value, option.value]\n : props.value.filter((item) => item !== option.value),\n ),\n }));\n const count = props.items\n ? props.items.filter((item) => item.checked).length\n : props.value.length;\n const title = titleProp ?? (typeof label === \"string\" ? label : \"Filter\");\n // The sheet always offers Clear while something's on; the popover only\n // when the caller asks for it.\n const clearInSheet =\n onClear ??\n (!props.items && count > 0 ? () => props.onValueChange([]) : undefined);\n\n const triggerProps = {\n \"aria-haspopup\": \"dialog\" as const,\n \"aria-expanded\": open,\n onClick: isMobile ? () => setOpen(true) : undefined,\n };\n const trigger = customTrigger ? (\n React.cloneElement(customTrigger, {\n ...triggerProps,\n onClick: (event: React.MouseEvent<HTMLElement>) => {\n customTrigger.props.onClick?.(event);\n triggerProps.onClick?.();\n },\n })\n ) : (\n <FilterChip\n size={size}\n selected={count > 0}\n count={count || undefined}\n className={className}\n {...triggerProps}\n >\n {label}\n <ChevronDown size={14} aria-hidden=\"true\" className=\"-mr-1\" />\n </FilterChip>\n );\n\n const list = <CheckboxList aria-label={title} items={items} />;\n\n // Phones: a bottom sheet, like Autocomplete and Select.\n if (isMobile)\n return (\n <>\n {trigger}\n <Sheet open={open} onOpenChange={setOpen}>\n <SheetContent\n side=\"bottom\"\n showCloseButton={false}\n overlayClassName=\"z-[1090] bg-black/25 backdrop-blur-[1px]\"\n aria-describedby={undefined}\n onOpenAutoFocus={(event) => {\n event.preventDefault();\n closeRef.current?.focus();\n }}\n className=\"flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]\"\n >\n <div className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">\n {title}\n </SheetTitle>\n <button\n ref={closeRef}\n type=\"button\"\n aria-label=\"Close\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onClick={() => setOpen(false)}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <div className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain px-2\">\n {list}\n </div>\n <div className=\"flex shrink-0 gap-2 border-t border-border px-4 pt-3\">\n {clearInSheet && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n scheme=\"neutral\"\n className=\"flex-1\"\n onClick={clearInSheet}\n >\n {clearLabel}\n </Button>\n )}\n {/* Outline, like Autocomplete's: ticks already applied, so\n Done only closes the sheet. */}\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"flex-1\"\n onClick={() => setOpen(false)}\n >\n Done\n </Button>\n </div>\n </SheetContent>\n </Sheet>\n </>\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>{trigger}</PopoverTrigger>\n <PopoverContent\n align={align}\n className={cn(\"w-56 p-0\", contentClassName)}\n >\n {list}\n {onClear && (\n <div className=\"border-t border-border p-option-inset\">\n <Button\n type=\"button\"\n variant=\"link\"\n scheme=\"primary\"\n size=\"xs\"\n onClick={onClear}\n >\n {clearLabel}\n </Button>\n </div>\n )}\n </PopoverContent>\n </Popover>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAaA;;;;;AAKG;AAEH;AACO;AAEP;AACO;AAcP;AACM;;AAqCN;AAuCA;;;;;;;AAOG;AACG;AACJ;AAWA;AACA;;;AAIA;;;;;;AASU;AAEP;AACH;AACE;AACA;AACF;;;;;AAOA;AACE;AACA;AACA;;AAEF;AAEI;AACA;;AAEE;;;;;AAmBN;AACE;;AAWU;AACF;AAgDV;AAwBF;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterinternship/components",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "workspaces": [
5
5
  "playground"
6
6
  ],