@obosbbl/grunnmuren-react 1.1.2 → 1.2.0

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: (props: RadioProps) => JSX.Element;
@@ -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: (props: RadioGroupProps) => JSX.Element;
@@ -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,
@@ -974,6 +974,101 @@ 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 = (props) => {
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
+ }, rest)), children]
1013
+ });
1014
+ };
1015
+ const RadioGroup = (props) => {
1016
+ const isControlled = "value" in props;
1017
+ const _a = props, {
1018
+ className,
1019
+ defaultValue,
1020
+ description,
1021
+ children,
1022
+ label,
1023
+ name,
1024
+ onChange: onChangeProp,
1025
+ required,
1026
+ value
1027
+ } = _a, rest = __objRest(_a, [
1028
+ "className",
1029
+ "defaultValue",
1030
+ "description",
1031
+ "children",
1032
+ "label",
1033
+ "name",
1034
+ "onChange",
1035
+ "required",
1036
+ "value"
1037
+ ]);
1038
+ const onChange = useCallback((event) => {
1039
+ const nextValue = event.target.value;
1040
+ onChangeProp == null ? void 0 : onChangeProp(nextValue);
1041
+ }, [onChangeProp]);
1042
+ const group = useMemo(() => ({
1043
+ defaultValue,
1044
+ isControlled,
1045
+ name,
1046
+ onChange,
1047
+ required,
1048
+ value
1049
+ }), [defaultValue, isControlled, name, onChange, required, value]);
1050
+ const groupId = useId();
1051
+ const labelId = `${groupId}:label`;
1052
+ const helpId = `${groupId}:help`;
1053
+ return /* @__PURE__ */ jsx(RadioContext.Provider, {
1054
+ value: group,
1055
+ children: /* @__PURE__ */ jsxs("div", __spreadProps(__spreadValues({
1056
+ "aria-describedby": description ? helpId : void 0,
1057
+ "aria-labelledby": label ? labelId : void 0,
1058
+ className: classNames(className, "flex flex-col gap-4"),
1059
+ role: "radiogroup"
1060
+ }, rest), {
1061
+ children: [label && /* @__PURE__ */ jsx(FormLabel, {
1062
+ id: labelId,
1063
+ isRequired: required,
1064
+ children: label
1065
+ }), children, /* @__PURE__ */ jsx(FormHelperText, {
1066
+ id: helpId,
1067
+ children: description
1068
+ })]
1069
+ }))
1070
+ });
1071
+ };
977
1072
  const Snackbar = (props) => {
978
1073
  const {
979
1074
  heading,
@@ -1172,4 +1267,4 @@ const Select = forwardRef((props, ref) => {
1172
1267
  })]
1173
1268
  });
1174
1269
  });
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 };
1270
+ 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.2",
3
+ "version": "1.2.0",
4
4
  "description": "OBOS Grunnmuren design system React components",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,32 +17,32 @@
17
17
  ],
18
18
  "types": "./dist/index.d.ts",
19
19
  "devDependencies": {
20
- "@babel/core": "7.18.6",
21
- "@obosbbl/grunnmuren-tailwind": "^0.4.2",
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.0",
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
+ "tailwindcss": "3.1.8",
36
+ "vite": "2.9.15",
37
+ "webpack": "5.74.0"
38
38
  },
39
39
  "dependencies": {
40
40
  "@obosbbl/grunnmuren-icons": "^0.3.0",
41
- "clsx": "1.2.0"
41
+ "clsx": "1.2.1"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^18",
45
- "@obosbbl/grunnmuren-tailwind": "^0.4.2"
45
+ "@obosbbl/grunnmuren-tailwind": "^0.5.0"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@obosbbl/grunnmuren-tailwind": {