@obosbbl/grunnmuren-react 2.0.0-canary.15 → 2.0.0-canary.17

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/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { CheckboxProps as CheckboxProps$1, CheckboxGroupProps as CheckboxGroupProps$1, ListBoxItemProps, ComboBoxProps, RadioGroupProps as RadioGroupProps$1, RadioProps as RadioProps$1, SelectProps as SelectProps$1, TextFieldProps as TextFieldProps$1, NumberFieldProps as NumberFieldProps$1, BreadcrumbProps as BreadcrumbProps$1, BreadcrumbsProps as BreadcrumbsProps$1 } from 'react-aria-components';
1
+ import { CheckboxProps as CheckboxProps$1, CheckboxGroupProps as CheckboxGroupProps$1, ListBoxItemProps, ComboBoxProps, RadioGroupProps as RadioGroupProps$1, RadioProps as RadioProps$1, SelectProps as SelectProps$1, TextFieldProps as TextFieldProps$1, NumberFieldProps as NumberFieldProps$1, ContextValue, BreadcrumbProps as BreadcrumbProps$1, BreadcrumbsProps as BreadcrumbsProps$1 } from 'react-aria-components';
2
2
  export { ListBoxItemProps as ComboboxItemProps, Form, ListBoxItemProps as SelectItemProps } from 'react-aria-components';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
- import { HTMLProps } from 'react';
5
+ import react__default, { HTMLProps, ForwardedRef } from 'react';
6
6
  import { VariantProps } from 'cva';
7
7
 
8
8
  type GrunnmurenProviderProps = {
@@ -17,6 +17,29 @@ type GrunnmurenProviderProps = {
17
17
  };
18
18
  declare function GrunnmurenProvider({ children, locale, navigate, }: GrunnmurenProviderProps): react_jsx_runtime.JSX.Element;
19
19
 
20
+ type AccordionProps = {
21
+ children: react__default.ReactNode;
22
+ /** Additional CSS className for the element. */
23
+ className?: string;
24
+ /** Additional style properties for the element. */
25
+ style?: react__default.CSSProperties;
26
+ };
27
+ type AccordionItemProps = {
28
+ children?: react__default.ReactNode;
29
+ /** Additional CSS className for the element. */
30
+ className?: string;
31
+ /** Additional style properties for the element. */
32
+ style?: react__default.CSSProperties;
33
+ /** Whether the accordion is open (controlled) */
34
+ isOpen?: boolean;
35
+ /** Whether the accordion is open by default (uncontrolled) */
36
+ defaultOpen?: boolean;
37
+ /** Handler that is called when the accordion's open state changes */
38
+ onOpenChange?: (isOpen: boolean) => void;
39
+ };
40
+ declare const _Accordion: react__default.ForwardRefExoticComponent<AccordionProps & react__default.RefAttributes<HTMLDivElement>>;
41
+ declare const _AccordionItem: react__default.ForwardRefExoticComponent<AccordionItemProps & react__default.RefAttributes<HTMLDivElement>>;
42
+
20
43
  /**
21
44
  * Figma: https://www.figma.com/file/9OvSg0ZXI5E1eQYi7AWiWn/Grunnmuren-2.0-%E2%94%82-Designsystem?node-id=30%3A2574&mode=dev
22
45
  */
@@ -497,15 +520,21 @@ type Props = VariantProps<typeof alertVariants> & {
497
520
  declare const Alertbox: ({ children, role, className, variant, isDismissable, isDismissed, onDismiss, isExpandable, }: Props) => react_jsx_runtime.JSX.Element | undefined;
498
521
 
499
522
  type HeadingProps = HTMLProps<HTMLHeadingElement> & {
500
- children: React.ReactNode;
523
+ children?: React.ReactNode;
501
524
  /** The level of the heading */
502
525
  level: 1 | 2 | 3 | 4 | 5 | 6;
526
+ /** @private Used internally for slotted components */
527
+ _innerWrapper?: (children: React.ReactNode) => React.ReactNode;
503
528
  };
504
- declare const Heading: ({ level, ...restProps }: HeadingProps) => react_jsx_runtime.JSX.Element;
529
+ declare const HeadingContext: react.Context<ContextValue<HeadingProps, HTMLHeadingElement>>;
530
+ declare const Heading: (props: HeadingProps, ref: ForwardedRef<HTMLHeadingElement>) => react_jsx_runtime.JSX.Element;
531
+ declare const ContentContext: react.Context<ContextValue<ContentProps, HTMLDivElement>>;
505
532
  type ContentProps = HTMLProps<HTMLDivElement> & {
506
533
  children: React.ReactNode;
534
+ /** @private Used internally for slotted components */
535
+ _outerWrapper?: (children: React.ReactNode) => React.ReactNode;
507
536
  };
508
- declare const Content: (props: ContentProps) => react_jsx_runtime.JSX.Element;
537
+ declare const Content: (props: ContentProps, ref: ForwardedRef<HTMLDivElement>) => string | number | boolean | Iterable<react.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
509
538
  type FooterProps = HTMLProps<HTMLDivElement> & {
510
539
  children: React.ReactNode;
511
540
  };
@@ -541,4 +570,4 @@ declare const _Breadcrumbs: react.ForwardRefExoticComponent<{
541
570
  style?: react.CSSProperties | undefined;
542
571
  } & Omit<BreadcrumbsProps$1<BreadcrumbProps>, "className" | "style"> & react.RefAttributes<HTMLOListElement>>;
543
572
 
544
- export { Alertbox, type Props as AlertboxProps, _Breadcrumb as Breadcrumb, type BreadcrumbProps, _Breadcrumbs as Breadcrumbs, type BreadcrumbsProps, _Button as Button, type ButtonProps, _Checkbox as Checkbox, _CheckboxGroup as CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, _Combobox as Combobox, ListBoxItem as ComboboxItem, type ComboboxProps, Content, type ContentProps, Footer, type FooterProps, GrunnmurenProvider, type GrunnmurenProviderProps, Heading, type HeadingProps, _NumberField as NumberField, type NumberFieldProps, _Radio as Radio, _RadioGroup as RadioGroup, type RadioGroupProps, type RadioProps, _Select as Select, ListBoxItem as SelectItem, type SelectProps, _TextArea as TextArea, type TextAreaProps, _TextField as TextField, type TextFieldProps };
573
+ export { _Accordion as Accordion, _AccordionItem as AccordionItem, type AccordionItemProps, type AccordionProps, Alertbox, type Props as AlertboxProps, _Breadcrumb as Breadcrumb, type BreadcrumbProps, _Breadcrumbs as Breadcrumbs, type BreadcrumbsProps, _Button as Button, type ButtonProps, _Checkbox as Checkbox, _CheckboxGroup as CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, _Combobox as Combobox, ListBoxItem as ComboboxItem, type ComboboxProps, Content, ContentContext, type ContentProps, Footer, type FooterProps, GrunnmurenProvider, type GrunnmurenProviderProps, Heading, HeadingContext, type HeadingProps, _NumberField as NumberField, type NumberFieldProps, _Radio as Radio, _RadioGroup as RadioGroup, type RadioGroupProps, type RadioProps, _Select as Select, ListBoxItem as SelectItem, type SelectProps, _TextArea as TextArea, type TextAreaProps, _TextField as TextField, type TextFieldProps };
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  'use client';
2
- import { I18nProvider, RouterProvider, Text, CheckboxContext, Checkbox as Checkbox$1, Label as Label$1, CheckboxGroup as CheckboxGroup$1, FieldError, ListBoxItem as ListBoxItem$1, ListBox as ListBox$1, ComboBox, Group, Input, Button as Button$1, Popover, RadioGroup as RadioGroup$1, Radio as Radio$1, Select as Select$1, SelectValue, TextField as TextField$1, TextArea as TextArea$1, NumberField as NumberField$1, useLocale, Breadcrumbs as Breadcrumbs$1, Breadcrumb as Breadcrumb$1, Link } from 'react-aria-components';
2
+ import { I18nProvider, RouterProvider, useContextProps, Provider, Text, CheckboxContext, Checkbox as Checkbox$1, Label as Label$1, CheckboxGroup as CheckboxGroup$1, FieldError, ListBoxItem as ListBoxItem$1, ListBox as ListBox$1, ComboBox, Group, Input, Button as Button$1, Popover, RadioGroup as RadioGroup$1, Radio as Radio$1, Select as Select$1, SelectValue, TextField as TextField$1, TextArea as TextArea$1, NumberField as NumberField$1, useLocale, Breadcrumbs as Breadcrumbs$1, Breadcrumb as Breadcrumb$1, Link } from 'react-aria-components';
3
3
  export { Form } from 'react-aria-components';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import { useLayoutEffect, forwardRef, useState, useRef, useId, Children } from 'react';
6
- import { cva, cx, compose } from 'cva';
7
- import { LoadingSpinner, Check, ChevronDown, Close, InfoCircle, CheckCircle, Warning, CloseCircle, ChevronRight } from '@obosbbl/grunnmuren-icons-react';
5
+ import { useLayoutEffect, createContext, forwardRef, Children, useId, useState, useRef } from 'react';
6
+ import { cx, cva, compose } from 'cva';
7
+ import { ChevronDown, LoadingSpinner, Check, Close, InfoCircle, CheckCircle, Warning, CloseCircle, ChevronRight } from '@obosbbl/grunnmuren-icons-react';
8
8
  import { mergeRefs } from '@react-aria/utils';
9
9
 
10
10
  function GrunnmurenProvider({ children, locale = 'nb', navigate }) {
@@ -22,6 +22,136 @@ const canUseDOM = ()=>{
22
22
  };
23
23
  const useClientLayoutEffect = canUseDOM() ? useLayoutEffect : ()=>{};
24
24
 
25
+ const HeadingContext = /*#__PURE__*/ createContext({});
26
+ const Heading = (props, ref)=>{
27
+ [props, ref] = useContextProps(props, ref, HeadingContext);
28
+ const { children, level, className, _innerWrapper: innerWrapper, ...restProps } = props;
29
+ const Element = `h${level}`;
30
+ return /*#__PURE__*/ jsx(Element, {
31
+ ...restProps,
32
+ className: className,
33
+ "data-slot": "heading",
34
+ children: innerWrapper ? innerWrapper(children) : children
35
+ });
36
+ };
37
+ const ContentContext = /*#__PURE__*/ createContext({});
38
+ const Content = (props, ref)=>{
39
+ [props, ref] = useContextProps(props, ref, ContentContext);
40
+ const { _outerWrapper: outerWrapper, ...restProps } = props;
41
+ const content = /*#__PURE__*/ jsx("div", {
42
+ ...restProps,
43
+ "data-slot": "content"
44
+ });
45
+ return outerWrapper ? outerWrapper(content) : content;
46
+ };
47
+ const Footer = (props)=>/*#__PURE__*/ jsx("div", {
48
+ ...props,
49
+ "data-slot": "footer"
50
+ });
51
+
52
+ function Accordion(props, ref) {
53
+ const { children, className, ...restProps } = props;
54
+ const childCount = Children.count(children);
55
+ return /*#__PURE__*/ jsx("div", {
56
+ ...restProps,
57
+ ref: ref,
58
+ className: cx('rounded-lg bg-white', className),
59
+ children: Children.map(children, (child, index)=>/*#__PURE__*/ jsxs(Fragment, {
60
+ children: [
61
+ child,
62
+ index < childCount - 1 && // Margin is added to enable support for containers with a background color
63
+ /*#__PURE__*/ jsx("hr", {
64
+ className: "mx-2 border-gray-light",
65
+ "aria-hidden": true
66
+ })
67
+ ]
68
+ }))
69
+ });
70
+ }
71
+ function AccordionItem(props, ref) {
72
+ const { className, children, defaultOpen = false, isOpen: controlledIsOpen, onOpenChange, ...restProps } = props;
73
+ const contentId = useId();
74
+ const buttonId = useId();
75
+ const isControlled = controlledIsOpen != null;
76
+ // This component has internal state that controls whether it is open or not,
77
+ // regardless if we are controlled or uncontrolled.
78
+ // If we are controlled, we use a layout effect to sync the controlled state
79
+ // with the internal state.
80
+ //
81
+ const [isOpen, setIsOpen] = useState(// If we are controlled, use that open state, otherwise use the uncontrolled
82
+ isControlled ? controlledIsOpen : defaultOpen);
83
+ useClientLayoutEffect(()=>{
84
+ if (isControlled) {
85
+ setIsOpen(controlledIsOpen);
86
+ }
87
+ }, [
88
+ controlledIsOpen,
89
+ isControlled
90
+ ]);
91
+ const handleOpenChange = ()=>{
92
+ const newOpenState = !isOpen;
93
+ if (!isControlled) {
94
+ setIsOpen(newOpenState);
95
+ }
96
+ // Always call the change handler, even if we're uncontrolled.
97
+ // Easier to add stuff such as tracking etc.
98
+ if (onOpenChange) {
99
+ onOpenChange(newOpenState);
100
+ }
101
+ };
102
+ return /*#__PURE__*/ jsx("div", {
103
+ ...restProps,
104
+ className: cx('group relative px-2', className),
105
+ ref: ref,
106
+ "data-open": isOpen,
107
+ children: /*#__PURE__*/ jsx(Provider, {
108
+ values: [
109
+ [
110
+ HeadingContext,
111
+ {
112
+ // Negative margin to strech the button to the entire with of the accordion (to support containers with a background color)
113
+ className: 'font-semibold leading-7 -mx-2',
114
+ // Supply a default level here to make this typecheck ok. Will be overwritten with the consumers set heading level anyways
115
+ level: 3,
116
+ _innerWrapper: (children)=>/*#__PURE__*/ jsxs("button", {
117
+ "aria-controls": contentId,
118
+ "aria-expanded": isOpen,
119
+ // Use outline with offset as focus indicator, this does not cover the left mint border on the expanded content and works with or without a background color on the accordion container
120
+ className: "flex min-h-[44px] w-full items-center justify-between gap-1.5 rounded-lg px-2 py-3.5 text-left focus-visible:outline focus-visible:outline-4 focus-visible:outline-offset-[-6px] focus-visible:outline-black",
121
+ id: buttonId,
122
+ onClick: handleOpenChange,
123
+ children: [
124
+ children,
125
+ /*#__PURE__*/ jsx(ChevronDown, {
126
+ className: cx('transition-transform duration-300 motion-reduce:transition-none', isOpen && 'rotate-180')
127
+ })
128
+ ]
129
+ })
130
+ }
131
+ ],
132
+ [
133
+ ContentContext,
134
+ {
135
+ className: // Uses pseudo element for vertical padding, since that doesn't affect the height when the accordion is closed
136
+ 'text-sm font-light leading-6 px-3.5 relative overflow-hidden border-mint border-l-[3px] before:relative before:block before:h-1.5 after:relative after:block after:h-1.5',
137
+ role: 'region',
138
+ // @ts-expect-error TODO: remove this expect-error when we're on React 19 https://github.com/facebook/react/issues/17157#issuecomment-2003750544
139
+ inert: isOpen ? undefined : 'true',
140
+ 'aria-labelledby': buttonId,
141
+ _outerWrapper: (children)=>/*#__PURE__*/ jsx("div", {
142
+ className: cx('grid transition-all duration-300 after:relative after:block after:h-0 after:transition-all after:duration-300 motion-reduce:transition-none', isOpen ? 'grid-rows-[1fr] after:h-3.5' : 'grid-rows-[0fr] '),
143
+ children: children
144
+ })
145
+ }
146
+ ]
147
+ ],
148
+ children: children
149
+ })
150
+ });
151
+ }
152
+ const _Accordion = /*#__PURE__*/ forwardRef(Accordion);
153
+ const _AccordionItem = /*#__PURE__*/ forwardRef(AccordionItem);
154
+
25
155
  /**
26
156
  * Figma: https://www.figma.com/file/9OvSg0ZXI5E1eQYi7AWiWn/Grunnmuren-2.0-%E2%94%82-Designsystem?node-id=30%3A2574&mode=dev
27
157
  */ const buttonVariants = cva({
@@ -765,22 +895,6 @@ const Alertbox = ({ children, role, className, variant = 'info', isDismissable =
765
895
  });
766
896
  };
767
897
 
768
- const Heading = ({ level, ...restProps })=>{
769
- const Heading = `h${level}`;
770
- return /*#__PURE__*/ jsx(Heading, {
771
- ...restProps,
772
- "data-slot": "heading"
773
- });
774
- };
775
- const Content = (props)=>/*#__PURE__*/ jsx("div", {
776
- ...props,
777
- "data-slot": "content"
778
- });
779
- const Footer = (props)=>/*#__PURE__*/ jsx("div", {
780
- ...props,
781
- "data-slot": "footer"
782
- });
783
-
784
898
  function Breadcrumbs(props, ref) {
785
899
  const { className, children, ...restProps } = props;
786
900
  return /*#__PURE__*/ jsx(Breadcrumbs$1, {
@@ -812,4 +926,4 @@ function Breadcrumb(props, ref) {
812
926
  }
813
927
  const _Breadcrumb = /*#__PURE__*/ forwardRef(Breadcrumb);
814
928
 
815
- export { Alertbox, _Breadcrumb as Breadcrumb, _Breadcrumbs as Breadcrumbs, _Button as Button, _Checkbox as Checkbox, _CheckboxGroup as CheckboxGroup, _Combobox as Combobox, ListBoxItem as ComboboxItem, Content, Footer, GrunnmurenProvider, Heading, _NumberField as NumberField, _Radio as Radio, _RadioGroup as RadioGroup, _Select as Select, ListBoxItem as SelectItem, _TextArea as TextArea, _TextField as TextField };
929
+ export { _Accordion as Accordion, _AccordionItem as AccordionItem, Alertbox, _Breadcrumb as Breadcrumb, _Breadcrumbs as Breadcrumbs, _Button as Button, _Checkbox as Checkbox, _CheckboxGroup as CheckboxGroup, _Combobox as Combobox, ListBoxItem as ComboboxItem, Content, ContentContext, Footer, GrunnmurenProvider, Heading, HeadingContext, _NumberField as NumberField, _Radio as Radio, _RadioGroup as RadioGroup, _Select as Select, ListBoxItem as SelectItem, _TextArea as TextArea, _TextField as TextField };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obosbbl/grunnmuren-react",
3
- "version": "2.0.0-canary.15",
3
+ "version": "2.0.0-canary.17",
4
4
  "description": "Grunnmuren components in React",
5
5
  "repository": {
6
6
  "url": "https://github.com/code-obos/grunnmuren"