@obosbbl/grunnmuren-react 2.0.0-canary.0 → 2.0.0-canary.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.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @obosbbl/grunnmuren-react
2
+
3
+ [![npm canary version](https://img.shields.io/npm/v/@obosbbl%2Fgrunnmuren-react/canary.svg)](https://www.npmjs.com/package/@obosbbl/grunnmuren-react)
4
+
5
+ Grunnmuren React components.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ # npm
11
+ npm install @obosbbl/grunnmuren-react@canary
12
+
13
+ # pnpm
14
+ pnpm add @obosbbl/grunnmuren-react@canary
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Before you start using the components you need to configure the [Tailwind preset](../tailwind/). Remember to add this package to the content scan.
20
+
21
+ ```js
22
+ import { Button } from '@obosbbl/grunnmuren-react/button';
23
+
24
+ export default function () {
25
+ return <Button>Click me</Button>;
26
+ }
27
+ ```
@@ -7,6 +7,7 @@ import { VariantProps } from 'cva';
7
7
  declare const buttonVariants: (props?: ({
8
8
  variant?: "primary" | "secondary" | "tertiary" | undefined;
9
9
  color?: "green" | "mint" | "white" | undefined;
10
+ isIconOnly?: boolean | undefined;
10
11
  } & ({
11
12
  class?: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any | {
12
13
  [x: string]: any;
@@ -7,6 +7,7 @@ import { VariantProps } from 'cva';
7
7
  declare const buttonVariants: (props?: ({
8
8
  variant?: "primary" | "secondary" | "tertiary" | undefined;
9
9
  color?: "green" | "mint" | "white" | undefined;
10
+ isIconOnly?: boolean | undefined;
10
11
  } & ({
11
12
  class?: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any | {
12
13
  [x: string]: any;
@@ -11,9 +11,7 @@ const useClientLayoutEffect = canUseDOM() ? useLayoutEffect : () => {
11
11
 
12
12
  const buttonVariants = cva({
13
13
  base: [
14
- "inline-flex min-h-[44px] cursor-pointer items-center justify-center whitespace-nowrap rounded-lg px-4 py-2 font-medium transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
15
- // Spaccing when using the button with icons
16
- "[&>svg]:first-of-type:mr-2.5 [&>svg]:last-of-type:ml-2.5"
14
+ "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"
17
15
  ],
18
16
  variants: {
19
17
  /**
@@ -34,6 +32,17 @@ const buttonVariants = cva({
34
32
  green: "focus-visible:ring-black",
35
33
  mint: "focus-visible:ring-mint focus-visible:ring-offset-green-dark",
36
34
  white: "focus-visible:ring-white focus-visible:ring-offset-blue"
35
+ },
36
+ /**
37
+ * When the button is without text, but with a single icon.
38
+ * @default false
39
+ */
40
+ isIconOnly: {
41
+ true: "p-2 [&>svg]:h-7 [&>svg]:w-7",
42
+ false: (
43
+ // The of-type classes takes care to add spacing when the button is used with icons
44
+ "px-4 py-2 [&>svg]:first-of-type:mr-2.5 [&>svg]:last-of-type:ml-2.5"
45
+ )
37
46
  }
38
47
  },
39
48
  compoundVariants: [
@@ -82,11 +91,21 @@ const buttonVariants = cva({
82
91
  ],
83
92
  defaultVariants: {
84
93
  variant: "primary",
85
- color: "green"
94
+ color: "green",
95
+ isIconOnly: false
86
96
  }
87
97
  });
88
98
  function Button(props) {
89
- const { children, className, color, loading, variant, style, ...restProps } = props;
99
+ const {
100
+ children,
101
+ className,
102
+ color,
103
+ isIconOnly,
104
+ loading,
105
+ variant,
106
+ style,
107
+ ...restProps
108
+ } = props;
90
109
  const buttonRef = useRef(null);
91
110
  const [widthOverride, setWidthOverride] = useState();
92
111
  useClientLayoutEffect(() => {
@@ -111,7 +130,7 @@ function Button(props) {
111
130
  Component,
112
131
  {
113
132
  "aria-busy": loading ? true : void 0,
114
- className: buttonVariants({ className, color, variant }),
133
+ className: buttonVariants({ className, color, isIconOnly, variant }),
115
134
  ref: buttonRef,
116
135
  style: {
117
136
  ...style,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obosbbl/grunnmuren-react",
3
- "version": "2.0.0-canary.0",
3
+ "version": "2.0.0-canary.1",
4
4
  "description": "Grunnmuren components in React",
5
5
  "repository": {
6
6
  "url": "https://github.com/code-obos/grunnmuren"