@uva-glass/component-library 3.2.2 → 3.3.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.
- package/dist/assets/RadioGroup.css +1 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +19 -0
- package/dist/components/RadioGroup/RadioGroup.js +51 -0
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts +5 -0
- package/dist/components/RadioGroup/RadioGroup.stories.js +48 -0
- package/dist/components/RadioGroup/RadioGroup.stories.js.map +1 -0
- package/dist/components/RadioGroup/Radiogroup.test.d.ts +0 -0
- package/dist/components/RadioGroup/Radiogroup.test.js +24 -0
- package/dist/components/RadioGroup/Radiogroup.test.js.map +1 -0
- package/dist/components/RadioGroup/index.d.ts +1 -0
- package/dist/components/RadioGroup/index.js +5 -0
- package/dist/components/RadioGroup/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._radio-group__header_omi6f_1{font-family:inherit;font-size:inherit;line-height:var(--line-height-s);margin:0;margin-bottom:.5rem}._radio-group_omi6f_1{background-color:var(--color-white);border:1px solid var(--color-grey-400);border-radius:.25rem;overflow:hidden}._radio-group__option_omi6f_16{cursor:pointer;display:flex;gap:1rem;padding:1rem}._radio-group__option_omi6f_16:not(:last-of-type){border-bottom:1px solid var(--color-grey-200)}._radio-group__option_omi6f_16:hover{background-color:var(--color-grey-100)}._radio-group__option--disabled_omi6f_31{cursor:default;pointer-events:none}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Option = {
|
|
2
|
+
id: string;
|
|
3
|
+
titleLabel: string;
|
|
4
|
+
descriptionLabel?: string;
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
7
|
+
export interface RadioGroupProps {
|
|
8
|
+
/** The label of the radio group */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Radio options. */
|
|
11
|
+
options: Option[];
|
|
12
|
+
/** Returns selected values as string */
|
|
13
|
+
onChange: (value: string) => void;
|
|
14
|
+
/** If true, the whole group will be disabled. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Represents a component for dispalying grouped styled radio buttons. */
|
|
18
|
+
export declare const RadioGroup: ({ label, options, onChange, disabled }: RadioGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsxs as g, Fragment as u, jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { useState as h } from "react";
|
|
3
|
+
import { c as f } from "../../clsx-OuTLNxxd.js";
|
|
4
|
+
import { RadioButton as k } from "../RadioButton/RadioButton.js";
|
|
5
|
+
import '../../assets/RadioGroup.css';const a = {
|
|
6
|
+
"radio-group__header": "_radio-group__header_omi6f_1",
|
|
7
|
+
"radio-group": "_radio-group_omi6f_1",
|
|
8
|
+
"radio-group__option": "_radio-group__option_omi6f_16",
|
|
9
|
+
"radio-group__option--disabled": "_radio-group__option--disabled_omi6f_31"
|
|
10
|
+
}, j = ({ label: d, options: n, onChange: p, disabled: t }) => {
|
|
11
|
+
const [s, c] = h(null), _ = (o) => {
|
|
12
|
+
t || (c(o), p(o));
|
|
13
|
+
};
|
|
14
|
+
return /* @__PURE__ */ g(u, { children: [
|
|
15
|
+
/* @__PURE__ */ i("h2", { className: a["radio-group__header"], children: d }),
|
|
16
|
+
/* @__PURE__ */ i("div", { className: a["radio-group"], children: n.map(({ id: o, descriptionLabel: l, titleLabel: m, value: r }) => /* @__PURE__ */ i(
|
|
17
|
+
"div",
|
|
18
|
+
{
|
|
19
|
+
className: f(a["radio-group__option"], {
|
|
20
|
+
[a["radio-group__option--disabled"]]: t
|
|
21
|
+
}),
|
|
22
|
+
onClick: () => _(r),
|
|
23
|
+
onKeyDown: (e) => {
|
|
24
|
+
(e.key === "Enter" || e.key === " ") && _(r);
|
|
25
|
+
},
|
|
26
|
+
role: "presentation",
|
|
27
|
+
children: /* @__PURE__ */ i(
|
|
28
|
+
k,
|
|
29
|
+
{
|
|
30
|
+
id: o,
|
|
31
|
+
label: m,
|
|
32
|
+
description: l,
|
|
33
|
+
name: d,
|
|
34
|
+
onChange: (e) => {
|
|
35
|
+
_(e.target.value);
|
|
36
|
+
},
|
|
37
|
+
value: r,
|
|
38
|
+
checked: s === r,
|
|
39
|
+
disabled: t,
|
|
40
|
+
gap: "large"
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
},
|
|
44
|
+
o
|
|
45
|
+
)) })
|
|
46
|
+
] });
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
j as RadioGroup
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=RadioGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroup.js","sources":["../../../src/components/RadioGroup/RadioGroup.tsx"],"sourcesContent":["import { useState } from 'react';\nimport clsx from 'clsx';\n\nimport styles from './RadioGroup.module.css';\n\nimport { RadioButton } from 'components/RadioButton/RadioButton';\n\ntype Option = {\n id: string;\n titleLabel: string;\n descriptionLabel?: string;\n value: string;\n};\n\nexport interface RadioGroupProps {\n /** The label of the radio group */\n label: string;\n /** Radio options. */\n options: Option[];\n /** Returns selected values as string */\n onChange: (value: string) => void;\n /** If true, the whole group will be disabled. */\n disabled?: boolean;\n}\n\n/** Represents a component for dispalying grouped styled radio buttons. */\nexport const RadioGroup = ({ label, options, onChange, disabled }: RadioGroupProps) => {\n const [selectedValue, setSelectedValue] = useState<string | null>(null);\n\n const handleSelection = (value: string) => {\n if (!disabled) {\n setSelectedValue(value);\n onChange(value);\n }\n };\n\n return (\n <>\n <h2 className={styles['radio-group__header']}>{label}</h2>\n <div className={styles['radio-group']}>\n {options.map(({ id, descriptionLabel, titleLabel, value }) => (\n <div\n className={clsx(styles['radio-group__option'], {\n [styles['radio-group__option--disabled']]: disabled,\n })}\n key={id}\n onClick={() => handleSelection(value)}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n handleSelection(value);\n }\n }}\n role=\"presentation\"\n >\n <RadioButton\n id={id}\n label={titleLabel}\n description={descriptionLabel}\n name={label}\n onChange={(event) => {\n handleSelection(event.target.value);\n }}\n value={value}\n checked={selectedValue === value}\n disabled={disabled}\n gap=\"large\"\n />\n </div>\n ))}\n </div>\n </>\n );\n};\n"],"names":["RadioGroup","label","options","onChange","disabled","selectedValue","setSelectedValue","useState","handleSelection","value","jsxs","Fragment","jsx","styles","id","descriptionLabel","titleLabel","clsx","event","RadioButton"],"mappings":";;;;;;;;;GA0BaA,IAAa,CAAC,EAAE,OAAAC,GAAO,SAAAC,GAAS,UAAAC,GAAU,UAAAC,QAAgC;AACrF,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAwB,IAAI,GAEhEC,IAAkB,CAACC,MAAkB;AACzC,IAAKL,MACHE,EAAiBG,CAAK,GACtBN,EAASM,CAAK;AAAA,EAElB;AAEA,SAEI,gBAAAC,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAA,gBAAAC,EAAC,MAAG,EAAA,WAAWC,EAAO,qBAAqB,GAAI,UAAMZ,GAAA;AAAA,IACpD,gBAAAW,EAAA,OAAA,EAAI,WAAWC,EAAO,aAAa,GACjC,UAAAX,EAAQ,IAAI,CAAC,EAAE,IAAAY,GAAI,kBAAAC,GAAkB,YAAAC,GAAY,OAAAP,QAChD,gBAAAG;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAWK,EAAKJ,EAAO,qBAAqB,GAAG;AAAA,UAC7C,CAACA,EAAO,+BAA+B,CAAC,GAAGT;AAAA,QAAA,CAC5C;AAAA,QAED,SAAS,MAAMI,EAAgBC,CAAK;AAAA,QACpC,WAAW,CAACS,MAAU;AACpB,WAAIA,EAAM,QAAQ,WAAWA,EAAM,QAAQ,QACzCV,EAAgBC,CAAK;AAAA,QAEzB;AAAA,QACA,MAAK;AAAA,QAEL,UAAA,gBAAAG;AAAA,UAACO;AAAA,UAAA;AAAA,YACC,IAAAL;AAAA,YACA,OAAOE;AAAA,YACP,aAAaD;AAAA,YACb,MAAMd;AAAA,YACN,UAAU,CAACiB,MAAU;AACH,cAAAV,EAAAU,EAAM,OAAO,KAAK;AAAA,YACpC;AAAA,YACA,OAAAT;AAAA,YACA,SAASJ,MAAkBI;AAAA,YAC3B,UAAAL;AAAA,YACA,KAAI;AAAA,UAAA;AAAA,QAAA;AAAA,MACN;AAAA,MArBKU;AAAA,IAAA,CAuBR,EACH,CAAA;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { RadioGroupProps } from './RadioGroup';
|
|
3
|
+
declare const _default: Meta<RadioGroupProps>;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare const RadioGroupExample: import('@storybook/core/csf').AnnotatedStoryFn<import('@storybook/react').ReactRenderer, RadioGroupProps>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { fn as a } from "../../index-DXR-TB1d.js";
|
|
3
|
+
import { RadioGroup as o } from "./RadioGroup.js";
|
|
4
|
+
const l = `
|
|
5
|
+
<RadioGroup label={label} options={options}
|
|
6
|
+
onChange={onChangeFunction} disabled={disabled} /> `, b = {
|
|
7
|
+
title: "Molecules/RadioGroup",
|
|
8
|
+
component: o,
|
|
9
|
+
argTypes: {
|
|
10
|
+
label: {
|
|
11
|
+
control: "text"
|
|
12
|
+
},
|
|
13
|
+
disabled: {
|
|
14
|
+
control: "boolean"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
parameters: {
|
|
18
|
+
inspectComponent: o,
|
|
19
|
+
codeString: l
|
|
20
|
+
}
|
|
21
|
+
}, n = [
|
|
22
|
+
{
|
|
23
|
+
id: "1",
|
|
24
|
+
titleLabel: "Option 1",
|
|
25
|
+
value: "option1"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "2",
|
|
29
|
+
titleLabel: "Option 2",
|
|
30
|
+
value: "option2"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "3",
|
|
34
|
+
titleLabel: "Option 3",
|
|
35
|
+
value: "option3"
|
|
36
|
+
}
|
|
37
|
+
], i = (e) => /* @__PURE__ */ t(o, { ...e }), p = i.bind({});
|
|
38
|
+
p.args = {
|
|
39
|
+
disabled: !1,
|
|
40
|
+
label: "Sample label",
|
|
41
|
+
options: n,
|
|
42
|
+
onChange: a()
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
p as RadioGroupExample,
|
|
46
|
+
b as default
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=RadioGroup.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroup.stories.js","sources":["../../../src/components/RadioGroup/RadioGroup.stories.tsx"],"sourcesContent":["import { fn } from '@storybook/test';\n\nimport type { Meta, StoryFn } from '@storybook/react';\nimport type { RadioGroupProps } from './RadioGroup';\n\nimport { RadioGroup } from './RadioGroup';\n\nconst codeString = `\n <RadioGroup label={label} options={options} \n onChange={onChangeFunction} disabled={disabled} /> `;\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n title: 'Molecules/RadioGroup',\n component: RadioGroup,\n argTypes: {\n label: {\n control: 'text',\n },\n disabled: {\n control: 'boolean',\n },\n },\n parameters: {\n inspectComponent: RadioGroup,\n codeString: codeString,\n },\n} as Meta<RadioGroupProps>;\n\nconst mockData = [\n {\n id: '1',\n titleLabel: 'Option 1',\n value: 'option1',\n },\n {\n id: '2',\n titleLabel: 'Option 2',\n value: 'option2',\n },\n {\n id: '3',\n titleLabel: 'Option 3',\n value: 'option3',\n },\n];\n\nconst Template: StoryFn<RadioGroupProps> = (args) => <RadioGroup {...args} />;\n\nexport const RadioGroupExample = Template.bind({});\nRadioGroupExample.args = {\n disabled: false,\n label: 'Sample label',\n options: mockData,\n onChange: fn(),\n};\n"],"names":["codeString","RadioGroup_stories","RadioGroup","mockData","Template","args","jsx","RadioGroupExample","fn"],"mappings":";;;AAOA,MAAMA,IAAa;AAAA;AAAA,0DAKJC,IAAA;AAAA,EACb,OAAO;AAAA,EACP,WAAWC;AAAA,EACX,UAAU;AAAA,IACR,OAAO;AAAA,MACL,SAAS;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACR,SAAS;AAAA,IAAA;AAAA,EAEb;AAAA,EACA,YAAY;AAAA,IACV,kBAAkBA;AAAA,IAClB,YAAAF;AAAA,EAAA;AAEJ,GAEMG,IAAW;AAAA,EACf;AAAA,IACE,IAAI;AAAA,IACJ,YAAY;AAAA,IACZ,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,IAAI;AAAA,IACJ,YAAY;AAAA,IACZ,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,IAAI;AAAA,IACJ,YAAY;AAAA,IACZ,OAAO;AAAA,EAAA;AAEX,GAEMC,IAAqC,CAACC,MAAU,gBAAAC,EAAAJ,GAAA,EAAY,GAAGG,GAAM,GAE9DE,IAAoBH,EAAS,KAAK,CAAE,CAAA;AACjDG,EAAkB,OAAO;AAAA,EACvB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAASJ;AAAA,EACT,UAAUK,EAAG;AACf;"}
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import "../../index-Z7qwJmRM.js";
|
|
3
|
+
import { r as l, s as t, f as s } from "../../react.esm-B8teOYlo.js";
|
|
4
|
+
import { RadioGroup as a } from "./RadioGroup.js";
|
|
5
|
+
const i = [
|
|
6
|
+
{ id: "1", titleLabel: "Option 1", value: "option1" },
|
|
7
|
+
{ id: "2", titleLabel: "Option 2", value: "option2" }
|
|
8
|
+
];
|
|
9
|
+
describe("RadioGroup", () => {
|
|
10
|
+
it("should render correctly", () => {
|
|
11
|
+
l(/* @__PURE__ */ n(a, { label: "Test Label", options: i, onChange: jest.fn() })), expect(t.getByText("Test Label")).toBeInTheDocument(), expect(t.getByText("Option 1")).toBeInTheDocument(), expect(t.getByText("Option 2")).toBeInTheDocument();
|
|
12
|
+
}), it("should call onChange when an option is selected", () => {
|
|
13
|
+
const e = jest.fn();
|
|
14
|
+
l(/* @__PURE__ */ n(a, { label: "Test Label", options: i, onChange: e }));
|
|
15
|
+
const o = t.getByLabelText("Option 1");
|
|
16
|
+
s.click(o), expect(e).toHaveBeenCalledWith("option1");
|
|
17
|
+
}), it("should not allow selection when disabled", () => {
|
|
18
|
+
const e = jest.fn();
|
|
19
|
+
l(/* @__PURE__ */ n(a, { label: "Test Label", options: i, onChange: e, disabled: !0 }));
|
|
20
|
+
const o = t.getByLabelText("Option 1");
|
|
21
|
+
s.click(o), expect(e).not.toHaveBeenCalled();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=Radiogroup.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Radiogroup.test.js","sources":["../../../src/components/RadioGroup/Radiogroup.test.tsx"],"sourcesContent":["import '@testing-library/jest-dom';\nimport { render, screen, fireEvent } from '@testing-library/react';\n\nimport { RadioGroup } from './RadioGroup';\n\nconst options = [\n { id: '1', titleLabel: 'Option 1', value: 'option1' },\n { id: '2', titleLabel: 'Option 2', value: 'option2' },\n];\n\ndescribe('RadioGroup', () => {\n it('should render correctly', () => {\n render(<RadioGroup label=\"Test Label\" options={options} onChange={jest.fn()} />);\n expect(screen.getByText('Test Label')).toBeInTheDocument();\n expect(screen.getByText('Option 1')).toBeInTheDocument();\n expect(screen.getByText('Option 2')).toBeInTheDocument();\n });\n\n it('should call onChange when an option is selected', () => {\n const handleChange = jest.fn();\n render(<RadioGroup label=\"Test Label\" options={options} onChange={handleChange} />);\n\n const option1 = screen.getByLabelText('Option 1');\n fireEvent.click(option1);\n expect(handleChange).toHaveBeenCalledWith('option1');\n });\n\n it('should not allow selection when disabled', () => {\n const handleChange = jest.fn();\n render(<RadioGroup label=\"Test Label\" options={options} onChange={handleChange} disabled />);\n\n const option1 = screen.getByLabelText('Option 1');\n fireEvent.click(option1);\n expect(handleChange).not.toHaveBeenCalled();\n });\n});\n"],"names":["options","render","jsx","RadioGroup","screen","handleChange","option1","fireEvent"],"mappings":";;;;AAKA,MAAMA,IAAU;AAAA,EACd,EAAE,IAAI,KAAK,YAAY,YAAY,OAAO,UAAU;AAAA,EACpD,EAAE,IAAI,KAAK,YAAY,YAAY,OAAO,UAAU;AACtD;AAEA,SAAS,cAAc,MAAM;AAC3B,KAAG,2BAA2B,MAAM;AAC3B,IAAAC,EAAA,gBAAAC,EAACC,KAAW,OAAM,cAAa,SAAAH,GAAkB,UAAU,KAAK,GAAG,EAAG,CAAA,CAAE,GAC/E,OAAOI,EAAO,UAAU,YAAY,CAAC,EAAE,kBAAkB,GACzD,OAAOA,EAAO,UAAU,UAAU,CAAC,EAAE,kBAAkB,GACvD,OAAOA,EAAO,UAAU,UAAU,CAAC,EAAE,kBAAkB;AAAA,EAAA,CACxD,GAED,GAAG,mDAAmD,MAAM;AACpD,UAAAC,IAAe,KAAK,GAAG;AAC7B,IAAAJ,oBAAQE,GAAW,EAAA,OAAM,cAAa,SAAAH,GAAkB,UAAUK,GAAc,CAAE;AAE5E,UAAAC,IAAUF,EAAO,eAAe,UAAU;AAChD,IAAAG,EAAU,MAAMD,CAAO,GAChB,OAAAD,CAAY,EAAE,qBAAqB,SAAS;AAAA,EAAA,CACpD,GAED,GAAG,4CAA4C,MAAM;AAC7C,UAAAA,IAAe,KAAK,GAAG;AACtB,IAAAJ,EAAA,gBAAAC,EAACC,KAAW,OAAM,cAAa,SAAAH,GAAkB,UAAUK,GAAc,UAAQ,GAAC,CAAA,CAAE;AAErF,UAAAC,IAAUF,EAAO,eAAe,UAAU;AAChD,IAAAG,EAAU,MAAMD,CAAO,GAChB,OAAAD,CAAY,EAAE,IAAI,iBAAiB;AAAA,EAAA,CAC3C;AACH,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './RadioGroup';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|