@betterinternship/components 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -25,7 +25,8 @@ export type FilterMenuOption = {
|
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* A filter chip that opens a checklist: each tick applies immediately, and
|
|
28
|
-
* the chip shows how many are on (in the selected, secondary style).
|
|
28
|
+
* the chip shows how many are on (in the selected, secondary style). On
|
|
29
|
+
* phones the checklist opens in a bottom sheet with Clear and Done.
|
|
29
30
|
*/
|
|
30
31
|
export declare function FilterMenu({ label, options, value, onValueChange, size, align, className, contentClassName, }: {
|
|
31
32
|
label: React.ReactNode;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { ChevronDown, X } from 'lucide-react';
|
|
4
5
|
import { cn } from '../utils.js';
|
|
6
|
+
import { useMobile } from '../hooks/use-mobile.js';
|
|
7
|
+
import { Button } from './button.js';
|
|
5
8
|
import { Checkbox } from './checkbox.js';
|
|
6
9
|
import { FilterChip } from './filter-chip.js';
|
|
7
10
|
import { Popover, PopoverTrigger, PopoverContent } from './popover.js';
|
|
11
|
+
import { Sheet, SheetContent, SheetTitle } from './sheet.js';
|
|
8
12
|
|
|
9
13
|
/*
|
|
10
14
|
* The shared look for every list of options (menus, selects, dropdowns,
|
|
@@ -22,17 +26,30 @@ function CheckboxList({ items, className, "aria-label": label, }) {
|
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
28
|
* A filter chip that opens a checklist: each tick applies immediately, and
|
|
25
|
-
* the chip shows how many are on (in the selected, secondary style).
|
|
29
|
+
* the chip shows how many are on (in the selected, secondary style). On
|
|
30
|
+
* phones the checklist opens in a bottom sheet with Clear and Done.
|
|
26
31
|
*/
|
|
27
32
|
function FilterMenu({ label, options, value, onValueChange, size = "sm", align = "start", className, contentClassName, }) {
|
|
33
|
+
const isMobile = useMobile();
|
|
34
|
+
const [open, setOpen] = React.useState(false);
|
|
35
|
+
const closeRef = React.useRef(null);
|
|
28
36
|
const count = value.length;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const title = typeof label === "string" ? label : "Filter";
|
|
38
|
+
const trigger = (jsxs(FilterChip, { size: size, selected: count > 0, count: count || undefined, className: className, "aria-haspopup": "dialog", "aria-expanded": open, onClick: isMobile ? () => setOpen(true) : undefined, children: [label, jsx(ChevronDown, { size: 14, "aria-hidden": "true", className: "-mr-1" })] }));
|
|
39
|
+
const list = (jsx(CheckboxList, { "aria-label": title, items: options.map((option) => ({
|
|
40
|
+
label: option.label,
|
|
41
|
+
checked: value.includes(option.value),
|
|
42
|
+
onCheckedChange: (on) => onValueChange(on
|
|
43
|
+
? [...value, option.value]
|
|
44
|
+
: value.filter((item) => item !== option.value)),
|
|
45
|
+
})) }));
|
|
46
|
+
// Phones: a bottom sheet, like Autocomplete and Select.
|
|
47
|
+
if (isMobile)
|
|
48
|
+
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) => {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
closeRef.current?.focus();
|
|
51
|
+
}, 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: [count > 0 && (jsx(Button, { type: "button", variant: "outline", className: "flex-1", onClick: () => onValueChange([]), children: "Clear" })), jsx(Button, { type: "button", className: "flex-1", onClick: () => setOpen(false), children: "Done" })] })] }) })] }));
|
|
52
|
+
return (jsxs(Popover, { children: [jsx(PopoverTrigger, { asChild: true, children: trigger }), jsx(PopoverContent, { align: align, className: cn("w-56 p-0", contentClassName), children: list })] }));
|
|
36
53
|
}
|
|
37
54
|
|
|
38
55
|
export { CheckboxList, FilterMenu, optionListClassName, optionRowClassName };
|
|
@@ -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 } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\nimport { Checkbox } from \"./checkbox\";\nimport { FilterChip } from \"./filter-chip\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\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\n/**\n * A filter chip that opens a checklist: each tick applies immediately, and\n * the chip shows how many are on (in the selected, secondary style).\n */\nexport function FilterMenu({\n label,\n options,\n value,\n onValueChange,\n size = \"sm\",\n align = \"start\",\n className,\n contentClassName,\n}: {\n label: React.ReactNode;\n options: FilterMenuOption[];\n /** The selected option values. */\n value: string[];\n onValueChange: (value: string[]) => void;\n size?: \"xs\" | \"sm\" | \"md\";\n align?: \"start\" | \"center\" | \"end\";\n className?: string;\n contentClassName?: string;\n}) {\n const count = value.length;\n
|
|
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\n/**\n * A filter chip that opens a checklist: each tick applies immediately, and\n * the chip shows how many are on (in the selected, secondary style). On\n * phones the checklist opens in a bottom sheet with Clear and Done.\n */\nexport function FilterMenu({\n label,\n options,\n value,\n onValueChange,\n size = \"sm\",\n align = \"start\",\n className,\n contentClassName,\n}: {\n label: React.ReactNode;\n options: FilterMenuOption[];\n /** The selected option values. */\n value: string[];\n onValueChange: (value: string[]) => void;\n size?: \"xs\" | \"sm\" | \"md\";\n align?: \"start\" | \"center\" | \"end\";\n className?: string;\n contentClassName?: string;\n}) {\n const isMobile = useMobile();\n const [open, setOpen] = React.useState(false);\n const closeRef = React.useRef<HTMLButtonElement>(null);\n const count = value.length;\n const title = typeof label === \"string\" ? label : \"Filter\";\n\n const trigger = (\n <FilterChip\n size={size}\n selected={count > 0}\n count={count || undefined}\n className={className}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={isMobile ? () => setOpen(true) : undefined}\n >\n {label}\n <ChevronDown size={14} aria-hidden=\"true\" className=\"-mr-1\" />\n </FilterChip>\n );\n\n const list = (\n <CheckboxList\n aria-label={title}\n items={options.map((option) => ({\n label: option.label,\n checked: value.includes(option.value),\n onCheckedChange: (on) =>\n onValueChange(\n on\n ? [...value, option.value]\n : value.filter((item) => item !== option.value),\n ),\n }))}\n />\n );\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 {count > 0 && (\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"flex-1\"\n onClick={() => onValueChange([])}\n >\n Clear\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>\n <PopoverTrigger asChild>{trigger}</PopoverTrigger>\n <PopoverContent\n align={align}\n className={cn(\"w-56 p-0\", contentClassName)}\n >\n {list}\n </PopoverContent>\n </Popover>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAaA;;;;;AAKG;AAEH;AACO;AAEP;AACO;AAcP;AACM;;AAqCN;AAIA;;;;AAIG;AACG;AAoBJ;AACA;;AAEA;AACA;AAEA;AAeA;;;;;AAUY;;;AAOZ;AACE;;AAWU;AACF;AA4CV;AAWF;;"}
|