@obosbbl/grunnmuren-react 1.1.1 → 1.2.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.
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export interface RadioProps extends React.ComponentPropsWithoutRef<'input'> {
3
+ children: React.ReactNode;
4
+ }
5
+ export declare const Radio: import("react").ForwardRefExoticComponent<RadioProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ export declare const RadioContext: import("react").Context<{
3
+ defaultValue?: string | undefined;
4
+ isControlled: boolean;
5
+ name?: string | undefined;
6
+ onChange?(event: React.ChangeEvent<HTMLInputElement>): void;
7
+ required?: boolean | undefined;
8
+ value?: string | undefined;
9
+ }>;
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ export interface RadioGroupProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onChange'> {
3
+ /** The value of the radio button to be initially selected. For uncontrolled usage */
4
+ defaultValue?: string;
5
+ /** Help text for the radio group. */
6
+ description?: string;
7
+ /** The `name` attribute for the radio buttons. */
8
+ name: string;
9
+ /** The label for the radio group. */
10
+ label?: string;
11
+ /** Event handler called when the value changes. */
12
+ onChange?(value: string): void;
13
+ /** Whether a value selection is required. */
14
+ required?: boolean;
15
+ /** The value of the selected radio button. For controlled usage */
16
+ value?: string;
17
+ }
18
+ export declare const RadioGroup: import("react").ForwardRefExoticComponent<RadioGroupProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,2 @@
1
+ export * from './Radio';
2
+ export * from './RadioGroup';
@@ -324,7 +324,7 @@ const Button = forwardRef((props, ref) => {
324
324
  const colorFromContext = useContext(ButtonColorContext);
325
325
  const color = colorFromProp != null ? colorFromProp : colorFromContext;
326
326
  const buttonVariation = buttonVariations[`${color}-${variant}`];
327
- const classes = classNames(className, buttonVariation, "button relative no-underline inline-block border-solid border-2 px-6 py-2 rounded-xl transition-all duration-200 font-medium w-fit disabled:pointer-events-none disabled:text-black disabled:bg-gray-light disabled:border-gray-light hover:rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-black ring-offset-2");
327
+ const classes = classNames(className, buttonVariation, "button");
328
328
  return /* @__PURE__ */ jsx(Fragment, {
329
329
  children: href ? /* @__PURE__ */ jsx("a", __spreadProps(__spreadValues({}, rest), {
330
330
  href,
@@ -479,7 +479,7 @@ const Checkbox = forwardRef((props, ref) => {
479
479
  className: classNames(className, "inline-flex cursor-pointer items-center"),
480
480
  children: [/* @__PURE__ */ jsx("input", __spreadProps(__spreadValues({
481
481
  id,
482
- className: classNames("checkbox checked:bg-green checked:border-green bg-whit mr-3 grid h-[1.25em] w-[1.25em] flex-none cursor-pointer appearance-none place-content-center rounded border-2 border-solid text-white focus:outline-none focus:ring-2", {
482
+ className: classNames("checkbox checked:bg-green checked:border-green mr-3 grid h-[1.25em] w-[1.25em] flex-none cursor-pointer appearance-none place-content-center rounded border-2 border-solid bg-white text-white focus:outline-none focus:ring-2", {
483
483
  "border-gray-dark focus:ring-black": !error,
484
484
  "border-red focus:ring-red": !!error
485
485
  }),
@@ -974,6 +974,103 @@ const NavbarExpandedMobileContent = (props) => {
974
974
  children: props.children
975
975
  });
976
976
  };
977
+ const RadioContext = createContext({
978
+ defaultValue: void 0,
979
+ isControlled: false,
980
+ name: void 0,
981
+ onChange() {
982
+ },
983
+ required: false,
984
+ value: void 0
985
+ });
986
+ const Radio = forwardRef((props, ref) => {
987
+ const _a = props, {
988
+ children,
989
+ className
990
+ } = _a, rest = __objRest(_a, [
991
+ "children",
992
+ "className"
993
+ ]);
994
+ const {
995
+ defaultValue,
996
+ isControlled,
997
+ name,
998
+ onChange,
999
+ required,
1000
+ value
1001
+ } = useContext(RadioContext);
1002
+ return /* @__PURE__ */ jsxs("label", {
1003
+ className: classNames(className, "cursor-pointer"),
1004
+ children: [/* @__PURE__ */ jsx("input", __spreadValues({
1005
+ className: "radio",
1006
+ defaultChecked: !isControlled ? rest.value === defaultValue : void 0,
1007
+ checked: isControlled ? rest.value === value : void 0,
1008
+ name,
1009
+ onChange: isControlled ? onChange : void 0,
1010
+ required,
1011
+ type: "radio",
1012
+ ref
1013
+ }, rest)), children]
1014
+ });
1015
+ });
1016
+ const RadioGroup = forwardRef((props, ref) => {
1017
+ const isControlled = "value" in props;
1018
+ const _a = props, {
1019
+ className,
1020
+ defaultValue,
1021
+ description,
1022
+ children,
1023
+ label,
1024
+ name,
1025
+ onChange: onChangeProp,
1026
+ required,
1027
+ value
1028
+ } = _a, rest = __objRest(_a, [
1029
+ "className",
1030
+ "defaultValue",
1031
+ "description",
1032
+ "children",
1033
+ "label",
1034
+ "name",
1035
+ "onChange",
1036
+ "required",
1037
+ "value"
1038
+ ]);
1039
+ const onChange = useCallback((event) => {
1040
+ const nextValue = event.target.value;
1041
+ onChangeProp == null ? void 0 : onChangeProp(nextValue);
1042
+ }, [onChangeProp]);
1043
+ const group = useMemo(() => ({
1044
+ defaultValue,
1045
+ isControlled,
1046
+ name,
1047
+ onChange,
1048
+ required,
1049
+ value
1050
+ }), [defaultValue, isControlled, name, onChange, required, value]);
1051
+ const groupId = useId();
1052
+ const labelId = `${groupId}:label`;
1053
+ const helpId = `${groupId}:help`;
1054
+ return /* @__PURE__ */ jsx(RadioContext.Provider, {
1055
+ value: group,
1056
+ children: /* @__PURE__ */ jsxs("div", __spreadProps(__spreadValues({
1057
+ "aria-describedby": description ? helpId : void 0,
1058
+ "aria-labelledby": label ? labelId : void 0,
1059
+ className: classNames(className, "flex flex-col gap-4"),
1060
+ role: "radiogroup",
1061
+ ref
1062
+ }, rest), {
1063
+ children: [label && /* @__PURE__ */ jsx(FormLabel, {
1064
+ id: labelId,
1065
+ isRequired: required,
1066
+ children: label
1067
+ }), children, /* @__PURE__ */ jsx(FormHelperText, {
1068
+ id: helpId,
1069
+ children: description
1070
+ })]
1071
+ }))
1072
+ });
1073
+ });
977
1074
  const Snackbar = (props) => {
978
1075
  const {
979
1076
  heading,
@@ -1172,4 +1269,4 @@ const Select = forwardRef((props, ref) => {
1172
1269
  })]
1173
1270
  });
1174
1271
  });
1175
- export { Alert, Banner, BannerImage, Button, ButtonColorContext, Campaign, Card, CardContent, CardImage, CardLinkOverlay, CardList, Checkbox, Footer, Form, FormError, FormErrorMessage, FormHeading, FormHelperText, FormLabel, FormSuccess, Hero, HeroActions, HeroContent, HeroContext, HeroImage, Input, Link, Navbar, NavbarCollapsible, NavbarContent, NavbarExpandedMobileContent, NavbarItem, NavbarItems, Select, Snackbar, SnackbarButton, SnackbarContent, StepList, StepListItem, TextArea, TextField, assignRef, useBlockBackgroundColor, useComposedRefs, useFallbackId, useFormControlValidity, useMedia, usePrefersReducedMotion, useScreenMaxWidthMd };
1272
+ export { Alert, Banner, BannerImage, Button, ButtonColorContext, Campaign, Card, CardContent, CardImage, CardLinkOverlay, CardList, Checkbox, Footer, Form, FormError, FormErrorMessage, FormHeading, FormHelperText, FormLabel, FormSuccess, Hero, HeroActions, HeroContent, HeroContext, HeroImage, Input, Link, Navbar, NavbarCollapsible, NavbarContent, NavbarExpandedMobileContent, NavbarItem, NavbarItems, Radio, RadioGroup, Select, Snackbar, SnackbarButton, SnackbarContent, StepList, StepListItem, TextArea, TextField, assignRef, useBlockBackgroundColor, useComposedRefs, useFallbackId, useFormControlValidity, useMedia, usePrefersReducedMotion, useScreenMaxWidthMd };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './Hero';
10
10
  export * from './Input';
11
11
  export * from './Link';
12
12
  export * from './Navbar';
13
+ export * from './Radio';
13
14
  export * from './Snackbar';
14
15
  export * from './StepList';
15
16
  export * from './TextArea';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obosbbl/grunnmuren-react",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "OBOS Grunnmuren design system React components",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,32 +17,33 @@
17
17
  ],
18
18
  "types": "./dist/index.d.ts",
19
19
  "devDependencies": {
20
- "@babel/core": "7.18.6",
21
- "@obosbbl/grunnmuren-tailwind": "^0.4.1",
22
- "@storybook/addon-controls": "6.5.9",
23
- "@storybook/addon-docs": "6.5.9",
20
+ "@babel/core": "7.18.10",
21
+ "@obosbbl/grunnmuren-tailwind": "0.5.1",
22
+ "@storybook/addon-controls": "6.5.10",
23
+ "@storybook/addon-docs": "6.5.10",
24
24
  "@storybook/addon-postcss": "2.0.0",
25
- "@storybook/builder-webpack5": "6.5.9",
26
- "@storybook/manager-webpack5": "6.5.9",
27
- "@storybook/react": "6.5.9",
28
- "@types/react": "18.0.14",
29
- "@types/react-dom": "18.0.5",
25
+ "@storybook/builder-webpack5": "6.5.10",
26
+ "@storybook/manager-webpack5": "6.5.10",
27
+ "@storybook/react": "6.5.10",
28
+ "@types/react": "18.0.17",
29
+ "@types/react-dom": "18.0.6",
30
30
  "@vitejs/plugin-react": "1.3.2",
31
- "postcss": "8.4.14",
31
+ "postcss": "8.4.16",
32
32
  "react": "18.2.0",
33
33
  "react-dom": "18.2.0",
34
34
  "require-from-string": "2.0.2",
35
- "tailwindcss": "3.1.4",
36
- "vite": "2.9.13",
37
- "webpack": "5.73.0"
35
+ "rimraf": "3.0.2",
36
+ "tailwindcss": "3.1.8",
37
+ "vite": "2.9.15",
38
+ "webpack": "5.74.0"
38
39
  },
39
40
  "dependencies": {
40
41
  "@obosbbl/grunnmuren-icons": "^0.3.0",
41
- "clsx": "1.2.0"
42
+ "clsx": "1.2.1"
42
43
  },
43
44
  "peerDependencies": {
44
- "react": "^18",
45
- "@obosbbl/grunnmuren-tailwind": "^0.4.1"
45
+ "@obosbbl/grunnmuren-tailwind": "^0.5.1",
46
+ "react": "^18"
46
47
  },
47
48
  "peerDependenciesMeta": {
48
49
  "@obosbbl/grunnmuren-tailwind": {
@@ -52,7 +53,7 @@
52
53
  "scripts": {
53
54
  "build": "pnpm run build:lib && pnpm run build:types",
54
55
  "build:lib": "vite build",
55
- "build:types": "tsc --emitDeclarationOnly --declaration",
56
+ "build:types": "tsc --emitDeclarationOnly --declaration && rimraf 'dist/**/stories/'",
56
57
  "dev": "start-storybook -p 6006 --ci",
57
58
  "build:storybook": "build-storybook"
58
59
  }