@betterinternship/components 3.2.3 → 3.2.4
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.
|
@@ -3,6 +3,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ChevronDown } from 'lucide-react';
|
|
5
5
|
import { cn } from '../utils.js';
|
|
6
|
+
import { interactiveSurfaceClassName } from '../lib/interaction-styles.js';
|
|
6
7
|
|
|
7
8
|
const CollapsibleContext = React.createContext(null);
|
|
8
9
|
function useCollapsible() {
|
|
@@ -20,7 +21,11 @@ function Collapsible({ open: controlledOpen, defaultOpen = false, onOpenChange,
|
|
|
20
21
|
setUncontrolledOpen(next);
|
|
21
22
|
onOpenChange?.(next);
|
|
22
23
|
};
|
|
23
|
-
return jsx(CollapsibleContext.Provider, { value: { open, toggle }, children: jsx("div", { className: cn("w-full overflow-hidden rounded-control-lg border border-input bg-background",
|
|
24
|
+
return jsx(CollapsibleContext.Provider, { value: { open, toggle }, children: jsx("div", { className: cn("w-full overflow-hidden rounded-control-lg border border-input bg-background",
|
|
25
|
+
// The ready-made panel, closed, answers like an interactive Card (lift,
|
|
26
|
+
// shadow, darker border). Open, it holds content being worked in, so it
|
|
27
|
+
// stays put and only the title row highlights.
|
|
28
|
+
title !== undefined && !open && cn(interactiveSurfaceClassName, "pointer-fine:hover:border-border-hover focus-within:border-border-hover"), className), "data-state": open ? "open" : "closed", ...props, children: title !== undefined ? jsxs(Fragment, { children: [jsxs(CollapsibleTrigger, { className: "flex w-full items-center justify-between gap-2 p-4 text-left text-sm font-semibold transition-colors duration-state hover:bg-muted motion-reduce:transition-none focus-visible:outline-3 focus-visible:-outline-offset-4 focus-visible:outline-landing-blue", children: [jsx("span", { children: title }), jsx(ChevronDown, { "aria-hidden": "true", className: cn("h-5 w-5 shrink-0 transition-transform duration-state ease-landing-out motion-reduce:transition-none", open && "rotate-180") })] }), jsx(CollapsibleContent, { divider: divider, children: jsx("div", { className: "px-4 pb-4 pt-4", children: children }) })] }) : children }) });
|
|
24
29
|
}
|
|
25
30
|
function CollapsibleTrigger({ asChild, className, children, onClick, ...props }) {
|
|
26
31
|
const { open, toggle } = useCollapsible();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collapsible.js","sources":["../../src/components/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { cn } from \"@/utils\";\n\ntype ContextValue = { open: boolean; toggle: () => void };\nconst CollapsibleContext = React.createContext<ContextValue | null>(null);\n\nfunction useCollapsible() {\n const context = React.useContext(CollapsibleContext);\n if (!context) throw new Error(\"Collapsible parts must be used inside Collapsible\");\n return context;\n}\n\nfunction Collapsible({ open: controlledOpen, defaultOpen = false, onOpenChange, className, children, title, divider = false, ...props }: {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n children: React.ReactNode;\n /** Optional heading for the ready-to-use collapsible panel. */\n title?: string;\n divider?: boolean;\n} & React.HTMLAttributes<HTMLDivElement>) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);\n const open = controlledOpen ?? uncontrolledOpen;\n const toggle = () => {\n const next = !open;\n if (controlledOpen === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n };\n\n return <CollapsibleContext.Provider value={{ open, toggle }}>\n <div className={cn(\"w-full overflow-hidden rounded-control-lg border border-input bg-background\", className)} data-state={open ? \"open\" : \"closed\"} {...props}>\n {title !== undefined ? <>\n <CollapsibleTrigger className=\"flex w-full items-center justify-between gap-2 p-4 text-left text-sm font-semibold transition-colors duration-state hover:bg-muted motion-reduce:transition-none focus-visible:outline-3 focus-visible:-outline-offset-4 focus-visible:outline-landing-blue\">\n <span>{title}</span>\n <ChevronDown aria-hidden=\"true\" className={cn(\"h-5 w-5 shrink-0 transition-transform duration-state ease-landing-out motion-reduce:transition-none\", open && \"rotate-180\")} />\n </CollapsibleTrigger>\n <CollapsibleContent divider={divider}>\n <div className=\"px-4 pb-4 pt-4\">{children}</div>\n </CollapsibleContent>\n </> : children}\n </div>\n </CollapsibleContext.Provider>;\n}\n\nfunction CollapsibleTrigger({ asChild, className, children, onClick, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement> & { asChild?: boolean }) {\n const { open, toggle } = useCollapsible();\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { onClick?.(event); if (!event.defaultPrevented) toggle(); };\n if (asChild && React.isValidElement(children)) {\n return React.cloneElement(children as React.ReactElement<any>, {\n ...props,\n 'aria-expanded': open,\n 'data-state': open ? 'open' : 'closed',\n onClick: handleClick,\n });\n }\n return <button type=\"button\" {...props} aria-expanded={open} data-state={open ? \"open\" : \"closed\"} className={className} onClick={handleClick}>{children}</button>;\n}\n\nfunction CollapsibleContent({ className, children, divider = false, style, ...props }: React.HTMLAttributes<HTMLDivElement> & { divider?: boolean }) {\n const { open } = useCollapsible();\n return <div className={cn(\"grid transition-[grid-template-rows] duration-state ease-landing-out motion-reduce:transition-none\", divider && open && \"border-t border-border\", className)} style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", ...style }} aria-hidden={!open} inert={!open} {...props}>\n <div className=\"min-h-0 overflow-hidden\">\n <div className={cn(\n \"origin-top transition-[opacity,transform,filter] duration-state ease-landing-out motion-reduce:transform-none motion-reduce:filter-none motion-reduce:transition-none\",\n open ? \"scale-100 opacity-100 blur-none\" : \"scale-[0.98] opacity-0 blur-sm\",\n )}>{children}</div>\n </div>\n </div>;\n}\n\nexport { Collapsible, CollapsibleTrigger, CollapsibleContent };\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collapsible.js","sources":["../../src/components/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { cn } from \"@/utils\";\nimport { interactiveSurfaceClassName } from \"@/lib/interaction-styles\";\n\ntype ContextValue = { open: boolean; toggle: () => void };\nconst CollapsibleContext = React.createContext<ContextValue | null>(null);\n\nfunction useCollapsible() {\n const context = React.useContext(CollapsibleContext);\n if (!context) throw new Error(\"Collapsible parts must be used inside Collapsible\");\n return context;\n}\n\nfunction Collapsible({ open: controlledOpen, defaultOpen = false, onOpenChange, className, children, title, divider = false, ...props }: {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n children: React.ReactNode;\n /** Optional heading for the ready-to-use collapsible panel. */\n title?: string;\n divider?: boolean;\n} & React.HTMLAttributes<HTMLDivElement>) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);\n const open = controlledOpen ?? uncontrolledOpen;\n const toggle = () => {\n const next = !open;\n if (controlledOpen === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n };\n\n return <CollapsibleContext.Provider value={{ open, toggle }}>\n <div className={cn(\n \"w-full overflow-hidden rounded-control-lg border border-input bg-background\",\n // The ready-made panel, closed, answers like an interactive Card (lift,\n // shadow, darker border). Open, it holds content being worked in, so it\n // stays put and only the title row highlights.\n title !== undefined && !open && cn(interactiveSurfaceClassName, \"pointer-fine:hover:border-border-hover focus-within:border-border-hover\"),\n className,\n )} data-state={open ? \"open\" : \"closed\"} {...props}>\n {title !== undefined ? <>\n <CollapsibleTrigger className=\"flex w-full items-center justify-between gap-2 p-4 text-left text-sm font-semibold transition-colors duration-state hover:bg-muted motion-reduce:transition-none focus-visible:outline-3 focus-visible:-outline-offset-4 focus-visible:outline-landing-blue\">\n <span>{title}</span>\n <ChevronDown aria-hidden=\"true\" className={cn(\"h-5 w-5 shrink-0 transition-transform duration-state ease-landing-out motion-reduce:transition-none\", open && \"rotate-180\")} />\n </CollapsibleTrigger>\n <CollapsibleContent divider={divider}>\n <div className=\"px-4 pb-4 pt-4\">{children}</div>\n </CollapsibleContent>\n </> : children}\n </div>\n </CollapsibleContext.Provider>;\n}\n\nfunction CollapsibleTrigger({ asChild, className, children, onClick, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement> & { asChild?: boolean }) {\n const { open, toggle } = useCollapsible();\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { onClick?.(event); if (!event.defaultPrevented) toggle(); };\n if (asChild && React.isValidElement(children)) {\n return React.cloneElement(children as React.ReactElement<any>, {\n ...props,\n 'aria-expanded': open,\n 'data-state': open ? 'open' : 'closed',\n onClick: handleClick,\n });\n }\n return <button type=\"button\" {...props} aria-expanded={open} data-state={open ? \"open\" : \"closed\"} className={className} onClick={handleClick}>{children}</button>;\n}\n\nfunction CollapsibleContent({ className, children, divider = false, style, ...props }: React.HTMLAttributes<HTMLDivElement> & { divider?: boolean }) {\n const { open } = useCollapsible();\n return <div className={cn(\"grid transition-[grid-template-rows] duration-state ease-landing-out motion-reduce:transition-none\", divider && open && \"border-t border-border\", className)} style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", ...style }} aria-hidden={!open} inert={!open} {...props}>\n <div className=\"min-h-0 overflow-hidden\">\n <div className={cn(\n \"origin-top transition-[opacity,transform,filter] duration-state ease-landing-out motion-reduce:transform-none motion-reduce:filter-none motion-reduce:transition-none\",\n open ? \"scale-100 opacity-100 blur-none\" : \"scale-[0.98] opacity-0 blur-sm\",\n )}>{children}</div>\n </div>\n </div>;\n}\n\nexport { Collapsible, CollapsibleTrigger, CollapsibleContent };\n"],"names":[],"mappings":";;;;;;;AAQA;AAEA;;AAEE;AAAc;AACd;AACF;AAEA;AAUE;AACA;;AAEE;;;AAEA;AACF;AAEA;;;;AAMI;AAcN;AAEA;;AAEE;AAAqH;;AAEnH;AACE;AACA;;AAEA;AACD;;AAEH;AACF;AAEA;AACE;AACA;AAQF;;"}
|