@obosbbl/grunnmuren-react 2.0.0-canary.5 → 2.0.0-canary.51
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 +122 -10
- package/dist/index.d.mts +507 -79
- package/dist/index.mjs +1161 -141
- package/package.json +9 -6
- package/dist/Button-client-wuoyidfi.js +0 -144
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obosbbl/grunnmuren-react",
|
|
3
|
-
"version": "2.0.0-canary.
|
|
3
|
+
"version": "2.0.0-canary.51",
|
|
4
4
|
"description": "Grunnmuren components in React",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/code-obos/grunnmuren"
|
|
@@ -18,13 +18,16 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@obosbbl/grunnmuren-icons-react": "^2.0.0-canary.
|
|
22
|
-
"@react-aria/utils": "^3.
|
|
23
|
-
"
|
|
24
|
-
"
|
|
21
|
+
"@obosbbl/grunnmuren-icons-react": "^2.0.0-canary.7",
|
|
22
|
+
"@react-aria/utils": "^3.25.1",
|
|
23
|
+
"@types/node": "^22.0.0",
|
|
24
|
+
"cva": "^1.0.0-0",
|
|
25
|
+
"react-aria": "^3.35.1",
|
|
26
|
+
"react-aria-components": "^1.3.1",
|
|
27
|
+
"react-stately": "^3.35.0"
|
|
25
28
|
},
|
|
26
29
|
"peerDependencies": {
|
|
27
|
-
"react": "^18"
|
|
30
|
+
"react": "^18 || ^19"
|
|
28
31
|
},
|
|
29
32
|
"scripts": {
|
|
30
33
|
"build": "bunchee"
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useLayoutEffect, forwardRef, useState, useRef } from 'react';
|
|
4
|
-
import { cva } from 'cva';
|
|
5
|
-
import { LoadingSpinner } from '@obosbbl/grunnmuren-icons-react';
|
|
6
|
-
import { mergeRefs } from '@react-aria/utils';
|
|
7
|
-
|
|
8
|
-
const canUseDOM = ()=>{
|
|
9
|
-
return typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
10
|
-
};
|
|
11
|
-
const useClientLayoutEffect = canUseDOM() ? useLayoutEffect : ()=>{};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Figma: https://www.figma.com/file/9OvSg0ZXI5E1eQYi7AWiWn/Grunnmuren-2.0-%E2%94%82-Designsystem?node-id=30%3A2574&mode=dev
|
|
15
|
-
*/ const buttonVariants = cva({
|
|
16
|
-
base: [
|
|
17
|
-
'inline-flex min-h-[44px] cursor-pointer items-center justify-center whitespace-nowrap rounded-lg font-medium transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2'
|
|
18
|
-
],
|
|
19
|
-
variants: {
|
|
20
|
-
/**
|
|
21
|
-
* The variant of the button
|
|
22
|
-
* @default primary
|
|
23
|
-
*/ variant: {
|
|
24
|
-
primary: 'no-underline',
|
|
25
|
-
// by using an inset box-shadow to emulate a border instead of an actual border, the button size will be equal regardless of the variant
|
|
26
|
-
secondary: 'no-underline shadow-[inset_0_0_0_2px]',
|
|
27
|
-
tertiary: 'underline hover:no-underline'
|
|
28
|
-
},
|
|
29
|
-
/**
|
|
30
|
-
* Adjusts the color of the button for usage on different backgrounds.
|
|
31
|
-
* @default green
|
|
32
|
-
*/ color: {
|
|
33
|
-
green: 'focus-visible:ring-black',
|
|
34
|
-
mint: 'focus-visible:ring-mint focus-visible:ring-offset-green-dark',
|
|
35
|
-
white: 'focus-visible:ring-white focus-visible:ring-offset-blue'
|
|
36
|
-
},
|
|
37
|
-
/**
|
|
38
|
-
* When the button is without text, but with a single icon.
|
|
39
|
-
* @default false
|
|
40
|
-
*/ isIconOnly: {
|
|
41
|
-
true: 'p-2 [&>svg]:h-7 [&>svg]:w-7',
|
|
42
|
-
false: // The of-type classes takes care to add spacing when the button is used with icons
|
|
43
|
-
'px-4 py-2 [&>svg]:first-of-type:mr-2.5 [&>svg]:last-of-type:ml-2.5'
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
compoundVariants: [
|
|
47
|
-
{
|
|
48
|
-
color: 'green',
|
|
49
|
-
variant: 'primary',
|
|
50
|
-
// Darken bg by 20% on hover. The color is manually crafted
|
|
51
|
-
className: 'bg-green text-white hover:bg-green-dark active:bg-[#007352]'
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
color: 'green',
|
|
55
|
-
variant: 'secondary',
|
|
56
|
-
className: 'bg-white text-black shadow-green hover:bg-green hover:text-white active:bg-green'
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
color: 'mint',
|
|
60
|
-
variant: 'primary',
|
|
61
|
-
// Darken bg by 20% on hover. The color is manually crafted
|
|
62
|
-
className: 'active:[#9ddac6] bg-mint text-black hover:bg-[#8dd4bd]'
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
color: 'mint',
|
|
66
|
-
variant: 'secondary',
|
|
67
|
-
className: 'text-mint shadow-mint hover:bg-mint hover:text-black'
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
color: 'mint',
|
|
71
|
-
variant: 'tertiary',
|
|
72
|
-
className: 'text-mint'
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
color: 'white',
|
|
76
|
-
variant: 'primary',
|
|
77
|
-
className: 'bg-white text-black hover:bg-sky active:bg-sky-light'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
color: 'white',
|
|
81
|
-
variant: 'secondary',
|
|
82
|
-
className: 'text-white shadow-white hover:bg-white hover:text-black'
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
color: 'white',
|
|
86
|
-
variant: 'tertiary',
|
|
87
|
-
className: 'text-white'
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
|
-
defaultVariants: {
|
|
91
|
-
variant: 'primary',
|
|
92
|
-
color: 'green',
|
|
93
|
-
isIconOnly: false
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
function Button(props, forwardedRef) {
|
|
97
|
-
const { children, className, color, isIconOnly, isLoading, variant, style, ...restProps } = props;
|
|
98
|
-
const [widthOverride, setWidthOverride] = useState();
|
|
99
|
-
const ownRef = useRef(null);
|
|
100
|
-
const ref = mergeRefs(ownRef, forwardedRef);
|
|
101
|
-
useClientLayoutEffect(()=>{
|
|
102
|
-
if (isLoading) {
|
|
103
|
-
const requestID = window.requestAnimationFrame(()=>{
|
|
104
|
-
setWidthOverride(ownRef.current?.getBoundingClientRect()?.width);
|
|
105
|
-
});
|
|
106
|
-
return ()=>{
|
|
107
|
-
setWidthOverride(undefined);
|
|
108
|
-
cancelAnimationFrame(requestID);
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}, [
|
|
112
|
-
isLoading,
|
|
113
|
-
children
|
|
114
|
-
]);
|
|
115
|
-
let Component = 'a';
|
|
116
|
-
if (props.href == null) {
|
|
117
|
-
// If we don't have a href, it's a button, and we add a fallback type button to prevent the button from accidentally submitting when in a form
|
|
118
|
-
Component = 'button';
|
|
119
|
-
restProps.type ??= 'button';
|
|
120
|
-
}
|
|
121
|
-
return(// @ts-expect-error TS doesn't agree here taht restProps is safe to spread, because restProps for anchors aren't type compatible with restProps for buttons, but that should be okay here
|
|
122
|
-
/*#__PURE__*/ jsx(Component, {
|
|
123
|
-
"aria-busy": isLoading ? true : undefined,
|
|
124
|
-
className: buttonVariants({
|
|
125
|
-
className,
|
|
126
|
-
color,
|
|
127
|
-
isIconOnly,
|
|
128
|
-
variant
|
|
129
|
-
}),
|
|
130
|
-
ref: ref,
|
|
131
|
-
style: {
|
|
132
|
-
...style,
|
|
133
|
-
width: widthOverride
|
|
134
|
-
},
|
|
135
|
-
...restProps,
|
|
136
|
-
children: widthOverride ? // remove margin for icon alignment
|
|
137
|
-
/*#__PURE__*/ jsx(LoadingSpinner, {
|
|
138
|
-
className: "!m-0 mx-auto animate-spin"
|
|
139
|
-
}) : children
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
const _Button = /*#__PURE__*/ forwardRef(Button);
|
|
143
|
-
|
|
144
|
-
export { _Button as _ };
|