@obosbbl/grunnmuren-react 2.0.0-canary.33 → 2.0.0-canary.34

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/README.md CHANGED
@@ -81,7 +81,7 @@ import { GrunnmurenProvider } from '@obosbbl/grunnmuren-react';
81
81
  import { useRouter } from 'next/navigation';
82
82
 
83
83
  export function Providers({children, locale}: { children: React.ReactNode, locale: string}) {
84
- let router = useRouter();
84
+ const router = useRouter();
85
85
 
86
86
  return (
87
87
  <GrunnmurenProvider locale={locale} navigate={router.push}>
@@ -116,6 +116,52 @@ export default function RootLayout({
116
116
  }
117
117
  ```
118
118
 
119
+ #### Basepath
120
+
121
+ If you're using a router such as Next's, then you can use the `useHref` prop to convert router-specific hrefs into native HTML hrefs. This is very useful for instance when using Next's [basepath](https://nextjs.org/docs/app/api-reference/next-config-js/basePath) setting, as you can use this to prepend the basepath to all links, similar to Next's `<Link>`.
122
+
123
+ **Before**
124
+
125
+ ```tsx
126
+ import Link from 'next/link';
127
+ import { Button } from '@obosbbl/grunnmuren-react';
128
+
129
+ // Notice how you have to handle the basepath yourself with Grunnmuren's component, but not with Next's.
130
+
131
+ <Link href="/bli-medlem">Bli medlem</Link>
132
+ <Button href="/medlem/bli-medlem">Bli medlem</Button>
133
+ ```
134
+
135
+ **After**
136
+
137
+ ```js
138
+ // app/providers.tsx
139
+ 'use client'
140
+ import { GrunnmurenProvider } from '@obosbbl/grunnmuren-react';
141
+ import { useRouter } from 'next/navigation';
142
+
143
+ export function Providers({children, locale}: { children: React.ReactNode, locale: string}) {
144
+ const router = useRouter();
145
+ const useHref = (href: string) => '/medlem' + href;
146
+
147
+ return (
148
+ <GrunnmurenProvider locale={locale} navigate={router.push} useHref={useHref}>
149
+ {children}
150
+ </GrunnmurenProvider>
151
+ )
152
+ }
153
+ ```
154
+
155
+ ```tsx
156
+ import Link from 'next/link';
157
+ import { Button } from '@obosbbl/grunnmuren-react';
158
+
159
+ // The hrefs are the same, as basepath is handled by the useHref hook in the provider.
160
+
161
+ <Link href="/bli-medlem">Bli medlem</Link>
162
+ <Button href="/bli-medlem">Bli medlem</Button>
163
+ ```
164
+
119
165
  ### Optimize bundle size by removing unused locales
120
166
 
121
167
  React Aria Components has built in support for over 30 languages, most of which will be unused in your application. To optimize your applications bundle size, it is recommended to use React Aria's build plugin to remove all the unused locales. Here is a quick example for Next.js:
package/dist/index.d.mts CHANGED
@@ -1,10 +1,11 @@
1
- import { ButtonProps as ButtonProps$1, Link, 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';
1
+ import { RouterProvider, ButtonProps as ButtonProps$1, Link, 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
5
  import react__default, { HTMLProps, ForwardedRef } from 'react';
6
6
  import { VariantProps } from 'cva';
7
7
 
8
+ type RouterProviderProps = React.ComponentProps<typeof RouterProvider>;
8
9
  type GrunnmurenProviderProps = {
9
10
  children: React.ReactNode;
10
11
  /**
@@ -12,10 +13,12 @@ type GrunnmurenProviderProps = {
12
13
  * @default nb
13
14
  */
14
15
  locale?: 'nb' | 'sv' | 'en';
15
- /** The router to use for navigation */
16
- navigate?: (path: string) => void;
16
+ /** The router to use for client side navigation */
17
+ navigate?: RouterProviderProps['navigate'];
18
+ /** Converts a router-specific href to a native HTML href, e.g. prepending a base path */
19
+ useHref?: RouterProviderProps['useHref'];
17
20
  };
18
- declare function GrunnmurenProvider({ children, locale, navigate, }: GrunnmurenProviderProps): react_jsx_runtime.JSX.Element;
21
+ declare function GrunnmurenProvider({ children, locale, navigate, useHref, }: GrunnmurenProviderProps): react_jsx_runtime.JSX.Element;
19
22
 
20
23
  type AccordionProps = {
21
24
  children: react__default.ReactNode;
@@ -135,7 +138,7 @@ declare const _Checkbox: react.ForwardRefExoticComponent<{
135
138
  errorMessage?: React.ReactNode;
136
139
  /** Additional style properties for the element. */
137
140
  style?: React.CSSProperties;
138
- } & Omit<CheckboxProps$1, "children" | "style" | "isDisabled" | "isIndeterminate" | "isReadOnly"> & react.RefAttributes<HTMLLabelElement>>;
141
+ } & Omit<CheckboxProps$1, "style" | "children" | "isDisabled" | "isIndeterminate" | "isReadOnly"> & react.RefAttributes<HTMLLabelElement>>;
139
142
 
140
143
  type CheckboxGroupProps = {
141
144
  children: React.ReactNode;
@@ -162,7 +165,7 @@ declare const _CheckboxGroup: react.ForwardRefExoticComponent<{
162
165
  label?: React.ReactNode;
163
166
  /** Additional style properties for the element. */
164
167
  style?: React.CSSProperties;
165
- } & Omit<CheckboxGroupProps$1, "children" | "className" | "style" | "isDisabled" | "isReadOnly" | "orientation"> & react.RefAttributes<HTMLDivElement>>;
168
+ } & Omit<CheckboxGroupProps$1, "style" | "children" | "className" | "isDisabled" | "isReadOnly" | "orientation"> & react.RefAttributes<HTMLDivElement>>;
166
169
 
167
170
  declare const ListBoxItem: (props: ListBoxItemProps) => react_jsx_runtime.JSX.Element;
168
171
 
@@ -205,7 +208,7 @@ declare const _Combobox: react.ForwardRefExoticComponent<{
205
208
  placeholder?: string;
206
209
  /** Additional style properties for the element. */
207
210
  style?: React.CSSProperties;
208
- } & Omit<ComboBoxProps<object>, "children" | "className" | "style" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLInputElement>>;
211
+ } & Omit<ComboBoxProps<object>, "style" | "children" | "className" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLInputElement>>;
209
212
 
210
213
  type RadioGroupProps = {
211
214
  children: React.ReactNode;
@@ -232,7 +235,7 @@ declare const _RadioGroup: react.ForwardRefExoticComponent<{
232
235
  label?: React.ReactNode;
233
236
  /** Additional style properties for the element. */
234
237
  style?: React.CSSProperties;
235
- } & Omit<RadioGroupProps$1, "children" | "className" | "style" | "isDisabled" | "isReadOnly" | "orientation"> & react.RefAttributes<HTMLDivElement>>;
238
+ } & Omit<RadioGroupProps$1, "style" | "children" | "className" | "isDisabled" | "isReadOnly" | "orientation"> & react.RefAttributes<HTMLDivElement>>;
236
239
 
237
240
  type RadioProps = {
238
241
  children: React.ReactNode;
@@ -251,7 +254,7 @@ declare const _Radio: react.ForwardRefExoticComponent<{
251
254
  description?: React.ReactNode;
252
255
  /** Additional style properties for the element. */
253
256
  style?: React.CSSProperties;
254
- } & Omit<RadioProps$1, "children" | "style" | "isDisabled"> & react.RefAttributes<HTMLLabelElement>>;
257
+ } & Omit<RadioProps$1, "style" | "children" | "isDisabled"> & react.RefAttributes<HTMLLabelElement>>;
255
258
 
256
259
  type SelectProps<T extends object> = {
257
260
  children: React.ReactNode;
@@ -282,7 +285,7 @@ declare const _Select: react.ForwardRefExoticComponent<{
282
285
  placeholder?: string;
283
286
  /** Additional style properties for the element. */
284
287
  style?: React.CSSProperties;
285
- } & Omit<SelectProps$1<object>, "children" | "className" | "style" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLButtonElement>>;
288
+ } & Omit<SelectProps$1<object>, "style" | "children" | "className" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLButtonElement>>;
286
289
 
287
290
  type TextAreaProps = {
288
291
  /** Additional CSS className for the element. */
@@ -321,7 +324,7 @@ declare const _TextArea: react.ForwardRefExoticComponent<{
321
324
  * @default 2
322
325
  */
323
326
  rows?: number;
324
- } & Omit<TextFieldProps$1, "children" | "className" | "style" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLTextAreaElement>>;
327
+ } & Omit<TextFieldProps$1, "style" | "children" | "className" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLTextAreaElement>>;
325
328
 
326
329
  type TextFieldProps = {
327
330
  /** Additional CSS className for the element. */
@@ -376,7 +379,7 @@ declare const _TextField: react.ForwardRefExoticComponent<{
376
379
  withAddonDivider?: boolean;
377
380
  /** Defines the number of characters and determines the width of the input element */
378
381
  size?: number;
379
- } & Omit<TextFieldProps$1, "children" | "className" | "style" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLInputElement>>;
382
+ } & Omit<TextFieldProps$1, "style" | "children" | "className" | "isDisabled" | "isReadOnly"> & react.RefAttributes<HTMLInputElement>>;
380
383
 
381
384
  type NumberFieldProps = {
382
385
  /** Additional CSS className for the element. */
@@ -439,7 +442,7 @@ declare const _NumberField: react.ForwardRefExoticComponent<{
439
442
  maxValue?: number;
440
443
  /** Defines the minimum numeric value */
441
444
  minValue?: number;
442
- } & Omit<NumberFieldProps$1, "children" | "className" | "style" | "isDisabled" | "isReadOnly" | "hideStepper"> & react.RefAttributes<HTMLInputElement>>;
445
+ } & Omit<NumberFieldProps$1, "style" | "children" | "className" | "isDisabled" | "isReadOnly" | "hideStepper"> & react.RefAttributes<HTMLInputElement>>;
443
446
 
444
447
  declare const alertVariants: (props?: ({
445
448
  variant?: "info" | "success" | "warning" | "danger" | undefined;
@@ -566,7 +569,7 @@ declare const _Breadcrumb: react.ForwardRefExoticComponent<{
566
569
  style?: React.CSSProperties;
567
570
  /** The URL to navigate to when clicking the breadcrumb. */
568
571
  href?: string;
569
- } & Omit<BreadcrumbProps$1, "className" | "style"> & react.RefAttributes<HTMLLIElement>>;
572
+ } & Omit<BreadcrumbProps$1, "style" | "className"> & react.RefAttributes<HTMLLIElement>>;
570
573
 
571
574
  type BreadcrumbsProps = {
572
575
  /** Additional CSS className for the element. */
@@ -579,7 +582,7 @@ declare const _Breadcrumbs: react.ForwardRefExoticComponent<{
579
582
  className?: string;
580
583
  /** Additional style properties for the element. */
581
584
  style?: React.CSSProperties;
582
- } & Omit<BreadcrumbsProps$1<BreadcrumbProps>, "className" | "style"> & react.RefAttributes<HTMLOListElement>>;
585
+ } & Omit<BreadcrumbsProps$1<BreadcrumbProps>, "style" | "className"> & react.RefAttributes<HTMLOListElement>>;
583
586
 
584
587
  type ButtonOrLinkProps = {
585
588
  children?: React.ReactNode;
package/dist/index.mjs CHANGED
@@ -2,26 +2,22 @@
2
2
  import { I18nProvider, RouterProvider, useContextProps, Provider, Link, Button as Button$1, Text, CheckboxContext, Checkbox as Checkbox$1, Label as Label$1, FieldError, CheckboxGroup as CheckboxGroup$1, ListBoxItem as ListBoxItem$1, ListBox as ListBox$1, ComboBox, Group, Input, 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 } 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, createContext, forwardRef, Children, useId, useState, useRef } from 'react';
5
+ import { createContext, forwardRef, Children, useId, useState, useRef } from 'react';
6
6
  import { cx, cva, compose } from 'cva';
7
7
  import { ChevronDown, LoadingSpinner, Check, Close, InfoCircle, CheckCircle, Warning, CloseCircle, ChevronRight, ChevronLeft } from '@obosbbl/grunnmuren-icons-react';
8
- import { mergeRefs } from '@react-aria/utils';
8
+ import { useLayoutEffect, mergeRefs } from '@react-aria/utils';
9
9
 
10
- function GrunnmurenProvider({ children, locale = 'nb', navigate }) {
10
+ function GrunnmurenProvider({ children, locale = 'nb', navigate, useHref }) {
11
11
  return /*#__PURE__*/ jsx(I18nProvider, {
12
12
  locale: locale,
13
13
  children: navigate ? /*#__PURE__*/ jsx(RouterProvider, {
14
14
  navigate: navigate,
15
+ useHref: useHref,
15
16
  children: children
16
17
  }) : children
17
18
  });
18
19
  }
19
20
 
20
- const canUseDOM = ()=>{
21
- return typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
22
- };
23
- const useClientLayoutEffect = canUseDOM() ? useLayoutEffect : ()=>{};
24
-
25
21
  const HeadingContext = /*#__PURE__*/ createContext({});
26
22
  const Heading = (props, ref)=>{
27
23
  [props, ref] = useContextProps(props, ref, HeadingContext);
@@ -80,7 +76,7 @@ function AccordionItem(props, ref) {
80
76
  //
81
77
  const [isOpen, setIsOpen] = useState(// If we are controlled, use that open state, otherwise use the uncontrolled
82
78
  isControlled ? controlledIsOpen : defaultOpen);
83
- useClientLayoutEffect(()=>{
79
+ useLayoutEffect(()=>{
84
80
  if (isControlled) {
85
81
  setIsOpen(controlledIsOpen);
86
82
  }
@@ -194,7 +190,7 @@ const _AccordionItem = /*#__PURE__*/ forwardRef(AccordionItem);
194
190
  {
195
191
  color: 'green',
196
192
  variant: 'secondary',
197
- className: 'bg-white text-black shadow-green hover:bg-green hover:text-white active:bg-green'
193
+ className: 'text-black shadow-green hover:bg-green hover:text-white active:bg-green'
198
194
  },
199
195
  {
200
196
  color: 'mint',
@@ -242,7 +238,7 @@ function Button(props, forwardedRef) {
242
238
  const [widthOverride, setWidthOverride] = useState();
243
239
  const ownRef = useRef(null);
244
240
  const ref = mergeRefs(ownRef, forwardedRef);
245
- useClientLayoutEffect(()=>{
241
+ useLayoutEffect(()=>{
246
242
  if (isLoading) {
247
243
  const requestID = window.requestAnimationFrame(()=>{
248
244
  setWidthOverride(ownRef.current?.getBoundingClientRect()?.width);
@@ -268,7 +264,7 @@ function Button(props, forwardedRef) {
268
264
  }) : _children;
269
265
  const style = {
270
266
  ..._style,
271
- widthOverride
267
+ width: widthOverride
272
268
  };
273
269
  return isLinkProps$1(restProps) ? /*#__PURE__*/ jsx(Link, {
274
270
  ...restProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obosbbl/grunnmuren-react",
3
- "version": "2.0.0-canary.33",
3
+ "version": "2.0.0-canary.34",
4
4
  "description": "Grunnmuren components in React",
5
5
  "repository": {
6
6
  "url": "https://github.com/code-obos/grunnmuren"