@sproutsocial/seeds-react-fieldset 1.0.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/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +7 -0
- package/dist/esm/index.js +75 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +45 -0
- package/src/Fieldset.stories.tsx +222 -0
- package/src/Fieldset.tsx +68 -0
- package/src/FieldsetTypes.ts +23 -0
- package/src/__tests__/Fieldset.test.tsx +31 -0
- package/src/__tests__/Fieldset.typetest.tsx +30 -0
- package/src/index.ts +5 -0
- package/src/styled.d.ts +7 -0
- package/src/styles.ts +25 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +12 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
yarn run v1.22.22
|
|
2
|
+
$ tsup --dts
|
|
3
|
+
CLI Building entry: src/index.ts
|
|
4
|
+
CLI Using tsconfig: tsconfig.json
|
|
5
|
+
CLI tsup v8.0.2
|
|
6
|
+
CLI Using tsup config: /home/runner/work/seeds/seeds/seeds-react/seeds-react-fieldset/tsup.config.ts
|
|
7
|
+
CLI Target: es2022
|
|
8
|
+
CLI Cleaning output folder
|
|
9
|
+
CJS Build start
|
|
10
|
+
ESM Build start
|
|
11
|
+
CJS dist/index.js 4.17 KB
|
|
12
|
+
CJS dist/index.js.map 4.56 KB
|
|
13
|
+
CJS ⚡️ Build success in 124ms
|
|
14
|
+
ESM dist/esm/index.js 2.08 KB
|
|
15
|
+
ESM dist/esm/index.js.map 4.45 KB
|
|
16
|
+
ESM ⚡️ Build success in 124ms
|
|
17
|
+
DTS Build start
|
|
18
|
+
DTS ⚡️ Build success in 16309ms
|
|
19
|
+
DTS dist/index.d.ts 1.30 KB
|
|
20
|
+
DTS dist/index.d.mts 1.30 KB
|
|
21
|
+
Done in 20.50s.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/Fieldset.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import Box2 from "@sproutsocial/seeds-react-box";
|
|
4
|
+
import Text from "@sproutsocial/seeds-react-text";
|
|
5
|
+
|
|
6
|
+
// src/styles.ts
|
|
7
|
+
import styled, { css } from "styled-components";
|
|
8
|
+
import Box from "@sproutsocial/seeds-react-box";
|
|
9
|
+
var ChildContainer = styled(Box)`
|
|
10
|
+
${(props) => props.layout === "vertical" && css`
|
|
11
|
+
margin-top: ${props.theme.space[300]};
|
|
12
|
+
|
|
13
|
+
&:first-child {
|
|
14
|
+
margin-top: 0;
|
|
15
|
+
}
|
|
16
|
+
`}
|
|
17
|
+
|
|
18
|
+
${(props) => props.layout === "horizontal" && css`
|
|
19
|
+
margin-left: ${props.theme.space[300]};
|
|
20
|
+
|
|
21
|
+
&:first-child {
|
|
22
|
+
margin-left: 0;
|
|
23
|
+
}
|
|
24
|
+
`}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
// src/Fieldset.tsx
|
|
28
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
var Fieldset = ({
|
|
30
|
+
layout = "vertical",
|
|
31
|
+
label,
|
|
32
|
+
helperText,
|
|
33
|
+
children,
|
|
34
|
+
...rest
|
|
35
|
+
}) => /* @__PURE__ */ jsxs(Box2, { as: "fieldset", border: "none", p: 0, "data-qa-fieldset": "", ...rest, children: [
|
|
36
|
+
typeof label === "string" ? /* @__PURE__ */ jsx(Fieldset.Legend, { children: label }) : label,
|
|
37
|
+
typeof helperText === "string" ? /* @__PURE__ */ jsx(Fieldset.HelperText, { children: helperText }) : helperText,
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
39
|
+
Box2,
|
|
40
|
+
{
|
|
41
|
+
display: "flex",
|
|
42
|
+
flexDirection: layout === "vertical" ? "column" : "row",
|
|
43
|
+
children: React.Children.map(children, (child) => /* @__PURE__ */ jsx(ChildContainer, { layout, children: child }))
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
] });
|
|
47
|
+
var FieldsetLegend = ({ children, ...rest }) => /* @__PURE__ */ jsx(
|
|
48
|
+
Text,
|
|
49
|
+
{
|
|
50
|
+
as: "legend",
|
|
51
|
+
fontSize: 300,
|
|
52
|
+
fontWeight: "semibold",
|
|
53
|
+
color: "text.body",
|
|
54
|
+
mb: 300,
|
|
55
|
+
...rest,
|
|
56
|
+
children
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
var FieldsetHelperText = ({ children, ...rest }) => /* @__PURE__ */ jsx(Text, { as: "p", fontSize: 200, mb: 300, ...rest, children });
|
|
60
|
+
FieldsetLegend.displayName = "Fieldset.Legend";
|
|
61
|
+
FieldsetHelperText.displayName = "Fieldset.HelperText";
|
|
62
|
+
Fieldset.Legend = FieldsetLegend;
|
|
63
|
+
Fieldset.HelperText = FieldsetHelperText;
|
|
64
|
+
var Fieldset_default = Fieldset;
|
|
65
|
+
|
|
66
|
+
// src/FieldsetTypes.ts
|
|
67
|
+
import "react";
|
|
68
|
+
|
|
69
|
+
// src/index.ts
|
|
70
|
+
var src_default = Fieldset_default;
|
|
71
|
+
export {
|
|
72
|
+
Fieldset_default as Fieldset,
|
|
73
|
+
src_default as default
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Fieldset.tsx","../../src/styles.ts","../../src/FieldsetTypes.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport Box from \"@sproutsocial/seeds-react-box\";\nimport Text from \"@sproutsocial/seeds-react-text\";\nimport { ChildContainer } from \"./styles\";\nimport type {\n TypeFieldsetProps,\n TypeFieldsetLegendProps,\n TypeFieldsetHelperText,\n} from \"./FieldsetTypes\";\n\n/**\n * Fieldset Component\n */\nconst Fieldset = ({\n layout = \"vertical\",\n label,\n helperText,\n children,\n ...rest\n}: TypeFieldsetProps) => (\n <Box as=\"fieldset\" border=\"none\" p={0} data-qa-fieldset=\"\" {...rest}>\n {typeof label === \"string\" ? (\n <Fieldset.Legend>{label}</Fieldset.Legend>\n ) : (\n label\n )}\n {typeof helperText === \"string\" ? (\n <Fieldset.HelperText>{helperText}</Fieldset.HelperText>\n ) : (\n helperText\n )}\n <Box\n display=\"flex\"\n flexDirection={layout === \"vertical\" ? \"column\" : \"row\"}\n >\n {React.Children.map(children, (child) => (\n <ChildContainer layout={layout}>{child}</ChildContainer>\n ))}\n </Box>\n </Box>\n);\n\nconst FieldsetLegend = ({ children, ...rest }: TypeFieldsetLegendProps) => (\n <Text\n as=\"legend\"\n fontSize={300}\n fontWeight=\"semibold\"\n color=\"text.body\"\n mb={300}\n {...rest}\n >\n {children}\n </Text>\n);\n\nconst FieldsetHelperText = ({ children, ...rest }: TypeFieldsetHelperText) => (\n <Text as=\"p\" fontSize={200} mb={300} {...rest}>\n {children}\n </Text>\n);\n\nFieldsetLegend.displayName = \"Fieldset.Legend\";\nFieldsetHelperText.displayName = \"Fieldset.HelperText\";\n\nFieldset.Legend = FieldsetLegend;\nFieldset.HelperText = FieldsetHelperText;\n\nexport default Fieldset;\n","import styled, { css } from \"styled-components\";\nimport type { TypeFieldsetChildContainerProps } from \"./FieldsetTypes\";\nimport Box from \"@sproutsocial/seeds-react-box\";\n\nexport const ChildContainer = styled(Box)<TypeFieldsetChildContainerProps>`\n ${(props) =>\n props.layout === \"vertical\" &&\n css`\n margin-top: ${props.theme.space[300]};\n\n &:first-child {\n margin-top: 0;\n }\n `}\n\n ${(props) =>\n props.layout === \"horizontal\" &&\n css`\n margin-left: ${props.theme.space[300]};\n\n &:first-child {\n margin-left: 0;\n }\n `}\n`;\n","import type { TypeTextProps } from \"@sproutsocial/seeds-react-text\";\nimport React from \"react\";\nimport type { TypeBoxProps } from \"@sproutsocial/seeds-react-box\";\n\nexport interface TypeFieldsetProps extends TypeBoxProps {\n /** Label text to display above the fieldset */\n label: React.ReactNode;\n helperText?: React.ReactNode;\n layout?: \"vertical\" | \"horizontal\";\n children: React.ReactNode;\n}\n\nexport interface TypeFieldsetChildContainerProps {\n layout: TypeFieldsetProps[\"layout\"];\n}\n\nexport interface TypeFieldsetLegendProps extends TypeTextProps {\n children: React.ReactNode;\n}\n\nexport interface TypeFieldsetHelperText extends TypeTextProps {\n children: React.ReactNode;\n}\n","import Fieldset from \"./Fieldset\";\n\nexport default Fieldset;\nexport { Fieldset };\nexport * from \"./FieldsetTypes\";\n"],"mappings":";AAAA,YAAY,WAAW;AACvB,OAAOA,UAAS;AAChB,OAAO,UAAU;;;ACFjB,OAAO,UAAU,WAAW;AAE5B,OAAO,SAAS;AAET,IAAM,iBAAiB,OAAO,GAAG;AAAA,IACpC,CAAC,UACD,MAAM,WAAW,cACjB;AAAA,oBACgB,MAAM,MAAM,MAAM,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,KAKrC;AAAA;AAAA,IAED,CAAC,UACD,MAAM,WAAW,gBACjB;AAAA,qBACiB,MAAM,MAAM,MAAM,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,KAKtC;AAAA;;;ADHH,SAEI,KAFJ;AAPF,IAAM,WAAW,CAAC;AAAA,EAChB,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MACE,qBAACC,MAAA,EAAI,IAAG,YAAW,QAAO,QAAO,GAAG,GAAG,oBAAiB,IAAI,GAAG,MAC5D;AAAA,SAAO,UAAU,WAChB,oBAAC,SAAS,QAAT,EAAiB,iBAAM,IAExB;AAAA,EAED,OAAO,eAAe,WACrB,oBAAC,SAAS,YAAT,EAAqB,sBAAW,IAEjC;AAAA,EAEF;AAAA,IAACA;AAAA,IAAA;AAAA,MACC,SAAQ;AAAA,MACR,eAAe,WAAW,aAAa,WAAW;AAAA,MAEjD,UAAM,eAAS,IAAI,UAAU,CAAC,UAC7B,oBAAC,kBAAe,QAAiB,iBAAM,CACxC;AAAA;AAAA,EACH;AAAA,GACF;AAGF,IAAM,iBAAiB,CAAC,EAAE,UAAU,GAAG,KAAK,MAC1C;AAAA,EAAC;AAAA;AAAA,IACC,IAAG;AAAA,IACH,UAAU;AAAA,IACV,YAAW;AAAA,IACX,OAAM;AAAA,IACN,IAAI;AAAA,IACH,GAAG;AAAA,IAEH;AAAA;AACH;AAGF,IAAM,qBAAqB,CAAC,EAAE,UAAU,GAAG,KAAK,MAC9C,oBAAC,QAAK,IAAG,KAAI,UAAU,KAAK,IAAI,KAAM,GAAG,MACtC,UACH;AAGF,eAAe,cAAc;AAC7B,mBAAmB,cAAc;AAEjC,SAAS,SAAS;AAClB,SAAS,aAAa;AAEtB,IAAO,mBAAQ;;;AElEf,OAAkB;;;ACClB,IAAO,cAAQ;","names":["Box","Box"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { TypeTextProps } from '@sproutsocial/seeds-react-text';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { TypeBoxProps } from '@sproutsocial/seeds-react-box';
|
|
5
|
+
|
|
6
|
+
interface TypeFieldsetProps extends TypeBoxProps {
|
|
7
|
+
/** Label text to display above the fieldset */
|
|
8
|
+
label: React.ReactNode;
|
|
9
|
+
helperText?: React.ReactNode;
|
|
10
|
+
layout?: "vertical" | "horizontal";
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
interface TypeFieldsetChildContainerProps {
|
|
14
|
+
layout: TypeFieldsetProps["layout"];
|
|
15
|
+
}
|
|
16
|
+
interface TypeFieldsetLegendProps extends TypeTextProps {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
interface TypeFieldsetHelperText extends TypeTextProps {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Fieldset Component
|
|
25
|
+
*/
|
|
26
|
+
declare const Fieldset: {
|
|
27
|
+
({ layout, label, helperText, children, ...rest }: TypeFieldsetProps): react_jsx_runtime.JSX.Element;
|
|
28
|
+
Legend: {
|
|
29
|
+
({ children, ...rest }: TypeFieldsetLegendProps): react_jsx_runtime.JSX.Element;
|
|
30
|
+
displayName: string;
|
|
31
|
+
};
|
|
32
|
+
HelperText: {
|
|
33
|
+
({ children, ...rest }: TypeFieldsetHelperText): react_jsx_runtime.JSX.Element;
|
|
34
|
+
displayName: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { Fieldset, type TypeFieldsetChildContainerProps, type TypeFieldsetHelperText, type TypeFieldsetLegendProps, type TypeFieldsetProps, Fieldset as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { TypeTextProps } from '@sproutsocial/seeds-react-text';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { TypeBoxProps } from '@sproutsocial/seeds-react-box';
|
|
5
|
+
|
|
6
|
+
interface TypeFieldsetProps extends TypeBoxProps {
|
|
7
|
+
/** Label text to display above the fieldset */
|
|
8
|
+
label: React.ReactNode;
|
|
9
|
+
helperText?: React.ReactNode;
|
|
10
|
+
layout?: "vertical" | "horizontal";
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
interface TypeFieldsetChildContainerProps {
|
|
14
|
+
layout: TypeFieldsetProps["layout"];
|
|
15
|
+
}
|
|
16
|
+
interface TypeFieldsetLegendProps extends TypeTextProps {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
interface TypeFieldsetHelperText extends TypeTextProps {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Fieldset Component
|
|
25
|
+
*/
|
|
26
|
+
declare const Fieldset: {
|
|
27
|
+
({ layout, label, helperText, children, ...rest }: TypeFieldsetProps): react_jsx_runtime.JSX.Element;
|
|
28
|
+
Legend: {
|
|
29
|
+
({ children, ...rest }: TypeFieldsetLegendProps): react_jsx_runtime.JSX.Element;
|
|
30
|
+
displayName: string;
|
|
31
|
+
};
|
|
32
|
+
HelperText: {
|
|
33
|
+
({ children, ...rest }: TypeFieldsetHelperText): react_jsx_runtime.JSX.Element;
|
|
34
|
+
displayName: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { Fieldset, type TypeFieldsetChildContainerProps, type TypeFieldsetHelperText, type TypeFieldsetLegendProps, type TypeFieldsetProps, Fieldset as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Fieldset: () => Fieldset_default,
|
|
34
|
+
default: () => src_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/Fieldset.tsx
|
|
39
|
+
var React = __toESM(require("react"));
|
|
40
|
+
var import_seeds_react_box2 = __toESM(require("@sproutsocial/seeds-react-box"));
|
|
41
|
+
var import_seeds_react_text = __toESM(require("@sproutsocial/seeds-react-text"));
|
|
42
|
+
|
|
43
|
+
// src/styles.ts
|
|
44
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
45
|
+
var import_seeds_react_box = __toESM(require("@sproutsocial/seeds-react-box"));
|
|
46
|
+
var ChildContainer = (0, import_styled_components.default)(import_seeds_react_box.default)`
|
|
47
|
+
${(props) => props.layout === "vertical" && import_styled_components.css`
|
|
48
|
+
margin-top: ${props.theme.space[300]};
|
|
49
|
+
|
|
50
|
+
&:first-child {
|
|
51
|
+
margin-top: 0;
|
|
52
|
+
}
|
|
53
|
+
`}
|
|
54
|
+
|
|
55
|
+
${(props) => props.layout === "horizontal" && import_styled_components.css`
|
|
56
|
+
margin-left: ${props.theme.space[300]};
|
|
57
|
+
|
|
58
|
+
&:first-child {
|
|
59
|
+
margin-left: 0;
|
|
60
|
+
}
|
|
61
|
+
`}
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
// src/Fieldset.tsx
|
|
65
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
66
|
+
var Fieldset = ({
|
|
67
|
+
layout = "vertical",
|
|
68
|
+
label,
|
|
69
|
+
helperText,
|
|
70
|
+
children,
|
|
71
|
+
...rest
|
|
72
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_seeds_react_box2.default, { as: "fieldset", border: "none", p: 0, "data-qa-fieldset": "", ...rest, children: [
|
|
73
|
+
typeof label === "string" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Fieldset.Legend, { children: label }) : label,
|
|
74
|
+
typeof helperText === "string" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Fieldset.HelperText, { children: helperText }) : helperText,
|
|
75
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
+
import_seeds_react_box2.default,
|
|
77
|
+
{
|
|
78
|
+
display: "flex",
|
|
79
|
+
flexDirection: layout === "vertical" ? "column" : "row",
|
|
80
|
+
children: React.Children.map(children, (child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChildContainer, { layout, children: child }))
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
] });
|
|
84
|
+
var FieldsetLegend = ({ children, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
85
|
+
import_seeds_react_text.default,
|
|
86
|
+
{
|
|
87
|
+
as: "legend",
|
|
88
|
+
fontSize: 300,
|
|
89
|
+
fontWeight: "semibold",
|
|
90
|
+
color: "text.body",
|
|
91
|
+
mb: 300,
|
|
92
|
+
...rest,
|
|
93
|
+
children
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
var FieldsetHelperText = ({ children, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_seeds_react_text.default, { as: "p", fontSize: 200, mb: 300, ...rest, children });
|
|
97
|
+
FieldsetLegend.displayName = "Fieldset.Legend";
|
|
98
|
+
FieldsetHelperText.displayName = "Fieldset.HelperText";
|
|
99
|
+
Fieldset.Legend = FieldsetLegend;
|
|
100
|
+
Fieldset.HelperText = FieldsetHelperText;
|
|
101
|
+
var Fieldset_default = Fieldset;
|
|
102
|
+
|
|
103
|
+
// src/FieldsetTypes.ts
|
|
104
|
+
var import_react = require("react");
|
|
105
|
+
|
|
106
|
+
// src/index.ts
|
|
107
|
+
var src_default = Fieldset_default;
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
Fieldset
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Fieldset.tsx","../src/styles.ts","../src/FieldsetTypes.ts"],"sourcesContent":["import Fieldset from \"./Fieldset\";\n\nexport default Fieldset;\nexport { Fieldset };\nexport * from \"./FieldsetTypes\";\n","import * as React from \"react\";\nimport Box from \"@sproutsocial/seeds-react-box\";\nimport Text from \"@sproutsocial/seeds-react-text\";\nimport { ChildContainer } from \"./styles\";\nimport type {\n TypeFieldsetProps,\n TypeFieldsetLegendProps,\n TypeFieldsetHelperText,\n} from \"./FieldsetTypes\";\n\n/**\n * Fieldset Component\n */\nconst Fieldset = ({\n layout = \"vertical\",\n label,\n helperText,\n children,\n ...rest\n}: TypeFieldsetProps) => (\n <Box as=\"fieldset\" border=\"none\" p={0} data-qa-fieldset=\"\" {...rest}>\n {typeof label === \"string\" ? (\n <Fieldset.Legend>{label}</Fieldset.Legend>\n ) : (\n label\n )}\n {typeof helperText === \"string\" ? (\n <Fieldset.HelperText>{helperText}</Fieldset.HelperText>\n ) : (\n helperText\n )}\n <Box\n display=\"flex\"\n flexDirection={layout === \"vertical\" ? \"column\" : \"row\"}\n >\n {React.Children.map(children, (child) => (\n <ChildContainer layout={layout}>{child}</ChildContainer>\n ))}\n </Box>\n </Box>\n);\n\nconst FieldsetLegend = ({ children, ...rest }: TypeFieldsetLegendProps) => (\n <Text\n as=\"legend\"\n fontSize={300}\n fontWeight=\"semibold\"\n color=\"text.body\"\n mb={300}\n {...rest}\n >\n {children}\n </Text>\n);\n\nconst FieldsetHelperText = ({ children, ...rest }: TypeFieldsetHelperText) => (\n <Text as=\"p\" fontSize={200} mb={300} {...rest}>\n {children}\n </Text>\n);\n\nFieldsetLegend.displayName = \"Fieldset.Legend\";\nFieldsetHelperText.displayName = \"Fieldset.HelperText\";\n\nFieldset.Legend = FieldsetLegend;\nFieldset.HelperText = FieldsetHelperText;\n\nexport default Fieldset;\n","import styled, { css } from \"styled-components\";\nimport type { TypeFieldsetChildContainerProps } from \"./FieldsetTypes\";\nimport Box from \"@sproutsocial/seeds-react-box\";\n\nexport const ChildContainer = styled(Box)<TypeFieldsetChildContainerProps>`\n ${(props) =>\n props.layout === \"vertical\" &&\n css`\n margin-top: ${props.theme.space[300]};\n\n &:first-child {\n margin-top: 0;\n }\n `}\n\n ${(props) =>\n props.layout === \"horizontal\" &&\n css`\n margin-left: ${props.theme.space[300]};\n\n &:first-child {\n margin-left: 0;\n }\n `}\n`;\n","import type { TypeTextProps } from \"@sproutsocial/seeds-react-text\";\nimport React from \"react\";\nimport type { TypeBoxProps } from \"@sproutsocial/seeds-react-box\";\n\nexport interface TypeFieldsetProps extends TypeBoxProps {\n /** Label text to display above the fieldset */\n label: React.ReactNode;\n helperText?: React.ReactNode;\n layout?: \"vertical\" | \"horizontal\";\n children: React.ReactNode;\n}\n\nexport interface TypeFieldsetChildContainerProps {\n layout: TypeFieldsetProps[\"layout\"];\n}\n\nexport interface TypeFieldsetLegendProps extends TypeTextProps {\n children: React.ReactNode;\n}\n\nexport interface TypeFieldsetHelperText extends TypeTextProps {\n children: React.ReactNode;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,IAAAA,0BAAgB;AAChB,8BAAiB;;;ACFjB,+BAA4B;AAE5B,6BAAgB;AAET,IAAM,qBAAiB,yBAAAC,SAAO,uBAAAC,OAAG;AAAA,IACpC,CAAC,UACD,MAAM,WAAW,cACjB;AAAA,oBACgB,MAAM,MAAM,MAAM,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,KAKrC;AAAA;AAAA,IAED,CAAC,UACD,MAAM,WAAW,gBACjB;AAAA,qBACiB,MAAM,MAAM,MAAM,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,KAKtC;AAAA;;;ADHH;AAPF,IAAM,WAAW,CAAC;AAAA,EAChB,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MACE,6CAAC,wBAAAC,SAAA,EAAI,IAAG,YAAW,QAAO,QAAO,GAAG,GAAG,oBAAiB,IAAI,GAAG,MAC5D;AAAA,SAAO,UAAU,WAChB,4CAAC,SAAS,QAAT,EAAiB,iBAAM,IAExB;AAAA,EAED,OAAO,eAAe,WACrB,4CAAC,SAAS,YAAT,EAAqB,sBAAW,IAEjC;AAAA,EAEF;AAAA,IAAC,wBAAAA;AAAA,IAAA;AAAA,MACC,SAAQ;AAAA,MACR,eAAe,WAAW,aAAa,WAAW;AAAA,MAEjD,UAAM,eAAS,IAAI,UAAU,CAAC,UAC7B,4CAAC,kBAAe,QAAiB,iBAAM,CACxC;AAAA;AAAA,EACH;AAAA,GACF;AAGF,IAAM,iBAAiB,CAAC,EAAE,UAAU,GAAG,KAAK,MAC1C;AAAA,EAAC,wBAAAC;AAAA,EAAA;AAAA,IACC,IAAG;AAAA,IACH,UAAU;AAAA,IACV,YAAW;AAAA,IACX,OAAM;AAAA,IACN,IAAI;AAAA,IACH,GAAG;AAAA,IAEH;AAAA;AACH;AAGF,IAAM,qBAAqB,CAAC,EAAE,UAAU,GAAG,KAAK,MAC9C,4CAAC,wBAAAA,SAAA,EAAK,IAAG,KAAI,UAAU,KAAK,IAAI,KAAM,GAAG,MACtC,UACH;AAGF,eAAe,cAAc;AAC7B,mBAAmB,cAAc;AAEjC,SAAS,SAAS;AAClB,SAAS,aAAa;AAEtB,IAAO,mBAAQ;;;AElEf,mBAAkB;;;AHClB,IAAO,cAAQ;","names":["import_seeds_react_box","styled","Box","Box","Text"]}
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sproutsocial/seeds-react-fieldset",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Seeds React Fieldset",
|
|
5
|
+
"author": "Sprout Social, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup --dts",
|
|
12
|
+
"build:debug": "tsup --dts --metafile",
|
|
13
|
+
"dev": "tsup --watch --dts",
|
|
14
|
+
"clean": "rm -rf .turbo dist",
|
|
15
|
+
"clean:modules": "rm -rf node_modules",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"test:watch": "jest --watch --coverage=false"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@sproutsocial/seeds-react-theme": "^*",
|
|
22
|
+
"@sproutsocial/seeds-react-system-props": "^*",
|
|
23
|
+
"@sproutsocial/seeds-react-box": "*",
|
|
24
|
+
"@sproutsocial/seeds-react-text": "*"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^18.0.0",
|
|
28
|
+
"@types/styled-components": "^5.1.26",
|
|
29
|
+
"@sproutsocial/eslint-config-seeds": "*",
|
|
30
|
+
"react": "^18.0.0",
|
|
31
|
+
"styled-components": "^5.2.3",
|
|
32
|
+
"tsup": "^8.0.2",
|
|
33
|
+
"typescript": "^5.6.2",
|
|
34
|
+
"@sproutsocial/seeds-tsconfig": "*",
|
|
35
|
+
"@sproutsocial/seeds-testing": "*",
|
|
36
|
+
"@sproutsocial/seeds-react-testing-library": "*",
|
|
37
|
+
"@sproutsocial/seeds-react-radio": "*"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"styled-components": "^5.2.3"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Box } from "@sproutsocial/seeds-react-box";
|
|
3
|
+
import { Button } from "@sproutsocial/seeds-react-button";
|
|
4
|
+
import { FormField } from "@sproutsocial/seeds-react-form-field";
|
|
5
|
+
import { Input } from "@sproutsocial/seeds-react-input";
|
|
6
|
+
import { Radio } from "@sproutsocial/seeds-react-radio";
|
|
7
|
+
import { Text } from "@sproutsocial/seeds-react-text";
|
|
8
|
+
import Fieldset from "./Fieldset";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: "Components/Form Elements/Fieldset",
|
|
12
|
+
component: Fieldset,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const RadioGroup = () => {
|
|
16
|
+
const values = ["Chicago", "Seattle", "Dublin"];
|
|
17
|
+
const [selectedValue, setSelectedValue] = useState(values[0]);
|
|
18
|
+
const isChecked = (value: string | undefined) => value === selectedValue;
|
|
19
|
+
// @ts-ignore - idk what to type this event as
|
|
20
|
+
const _handleChange = (e) => {
|
|
21
|
+
e.target as HTMLInputElement;
|
|
22
|
+
setSelectedValue(e.target.value);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Box width="443px">
|
|
27
|
+
<Fieldset label="Select a location">
|
|
28
|
+
{values.map((value) => (
|
|
29
|
+
<Radio
|
|
30
|
+
id={value}
|
|
31
|
+
value={value}
|
|
32
|
+
name="location"
|
|
33
|
+
label={value}
|
|
34
|
+
checked={isChecked(value)}
|
|
35
|
+
onChange={_handleChange}
|
|
36
|
+
/>
|
|
37
|
+
))}
|
|
38
|
+
</Fieldset>
|
|
39
|
+
</Box>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
RadioGroup.story = {
|
|
44
|
+
name: "Radio group",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const inputs = () => (
|
|
48
|
+
<Box width="443px">
|
|
49
|
+
<Fieldset
|
|
50
|
+
label={
|
|
51
|
+
<Text fontSize={400} color="text.headline">
|
|
52
|
+
Your Name
|
|
53
|
+
</Text>
|
|
54
|
+
}
|
|
55
|
+
>
|
|
56
|
+
<FormField label="First Name">
|
|
57
|
+
{(props) => <Input {...props} name="first-name" />}
|
|
58
|
+
</FormField>
|
|
59
|
+
<FormField label="Last Name">
|
|
60
|
+
{(props) => <Input {...props} name="last-name" />}
|
|
61
|
+
</FormField>
|
|
62
|
+
</Fieldset>
|
|
63
|
+
</Box>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
inputs.story = {
|
|
67
|
+
name: "Inputs",
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const HorizontalRadios = () => {
|
|
71
|
+
const values = ["Chicago", "Seattle", "Dublin"];
|
|
72
|
+
const [selectedValue, setSelectedValue] = useState(values[0]);
|
|
73
|
+
const isChecked = (value: string | undefined) => value === selectedValue;
|
|
74
|
+
// @ts-ignore - idk what to type this event as
|
|
75
|
+
const _handleChange = (e) => {
|
|
76
|
+
e.target as HTMLInputElement;
|
|
77
|
+
setSelectedValue(e.target.value);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Box width="443px">
|
|
82
|
+
<Fieldset label="Select a location" layout="horizontal">
|
|
83
|
+
{values.map((value) => (
|
|
84
|
+
<Radio
|
|
85
|
+
id={value}
|
|
86
|
+
value={value}
|
|
87
|
+
name="location"
|
|
88
|
+
label={value}
|
|
89
|
+
checked={isChecked(value)}
|
|
90
|
+
onChange={_handleChange}
|
|
91
|
+
/>
|
|
92
|
+
))}
|
|
93
|
+
</Fieldset>
|
|
94
|
+
</Box>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
HorizontalRadios.story = {
|
|
99
|
+
name: "Horizontal Radios",
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const horizontalInputs = () => (
|
|
103
|
+
<Box width="443px">
|
|
104
|
+
<Fieldset label="Your Name" layout="horizontal">
|
|
105
|
+
<FormField label="First Name">
|
|
106
|
+
{(props) => <Input {...props} name="first-name" />}
|
|
107
|
+
</FormField>
|
|
108
|
+
<FormField label="Last Name">
|
|
109
|
+
{(props) => <Input {...props} name="last-name" />}
|
|
110
|
+
</FormField>
|
|
111
|
+
</Fieldset>
|
|
112
|
+
</Box>
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
horizontalInputs.story = {
|
|
116
|
+
name: "Horizontal Inputs",
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const ValidateInput = () => {
|
|
120
|
+
const [firstNameValue, setFirstNameValue] = useState("");
|
|
121
|
+
const [lastNameValue, setLastNameValue] = useState("");
|
|
122
|
+
const [validation, setValidation] = useState({
|
|
123
|
+
firstName: false,
|
|
124
|
+
lastName: false,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const firstNameValidation = firstNameValue === "Justyn" ? false : true;
|
|
128
|
+
const lastNameValidation = lastNameValue === "Howard" ? false : true;
|
|
129
|
+
|
|
130
|
+
const validate = () => {
|
|
131
|
+
setValidation({
|
|
132
|
+
firstName: firstNameValidation,
|
|
133
|
+
lastName: lastNameValidation,
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// @ts-ignore - idk what to type this event as
|
|
138
|
+
const handleFirstNameOnChange = ({ target }) => {
|
|
139
|
+
if (firstNameValue.length > 0 && validation.firstName) {
|
|
140
|
+
setValidation({
|
|
141
|
+
firstName: false,
|
|
142
|
+
lastName: lastNameValidation,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
setFirstNameValue(target.value);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// @ts-ignore - idk what to type this event as
|
|
149
|
+
const handleLastNameOnChange = ({ target }) => {
|
|
150
|
+
if (lastNameValue.length > 0 && validation.lastName) {
|
|
151
|
+
setValidation({
|
|
152
|
+
firstName: firstNameValidation,
|
|
153
|
+
lastName: false,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
setLastNameValue(target.value);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<Box width="443px">
|
|
161
|
+
<Fieldset label="Your Name" aria-live="polite">
|
|
162
|
+
<FormField
|
|
163
|
+
label="First Name"
|
|
164
|
+
isInvalid={validation.firstName}
|
|
165
|
+
error='First name must be "Justyn" to continue'
|
|
166
|
+
>
|
|
167
|
+
{(props) => (
|
|
168
|
+
<Input
|
|
169
|
+
{...props}
|
|
170
|
+
value={firstNameValue}
|
|
171
|
+
onChange={(e) => handleFirstNameOnChange(e)}
|
|
172
|
+
name="first-name"
|
|
173
|
+
/>
|
|
174
|
+
)}
|
|
175
|
+
</FormField>
|
|
176
|
+
<FormField
|
|
177
|
+
label="Last Name"
|
|
178
|
+
isInvalid={validation.lastName}
|
|
179
|
+
error='Last name must be "Howard" to continue'
|
|
180
|
+
>
|
|
181
|
+
{(props) => (
|
|
182
|
+
<Input
|
|
183
|
+
{...props}
|
|
184
|
+
value={lastNameValue}
|
|
185
|
+
onChange={(e) => handleLastNameOnChange(e)}
|
|
186
|
+
name="last-name"
|
|
187
|
+
/>
|
|
188
|
+
)}
|
|
189
|
+
</FormField>
|
|
190
|
+
<Button type="submit" appearance="primary" onClick={validate}>
|
|
191
|
+
Submit
|
|
192
|
+
</Button>
|
|
193
|
+
</Fieldset>
|
|
194
|
+
</Box>
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
ValidateInput.storyName = "Validation";
|
|
199
|
+
|
|
200
|
+
export const customFieldset = () => (
|
|
201
|
+
<Box width="443px">
|
|
202
|
+
<Fieldset
|
|
203
|
+
label={
|
|
204
|
+
<Fieldset.Legend fontSize={500} color="green.400">
|
|
205
|
+
What's your sign?
|
|
206
|
+
</Fieldset.Legend>
|
|
207
|
+
}
|
|
208
|
+
helperText={
|
|
209
|
+
<Fieldset.HelperText fontSize={400} color="blue.700">
|
|
210
|
+
Mucho Mucho Amor
|
|
211
|
+
</Fieldset.HelperText>
|
|
212
|
+
}
|
|
213
|
+
>
|
|
214
|
+
<FormField label="Name">
|
|
215
|
+
{(props) => <Input {...props} name="name" />}
|
|
216
|
+
</FormField>
|
|
217
|
+
<FormField label="Zodiac">
|
|
218
|
+
{(props) => <Input {...props} name="zodiac" />}
|
|
219
|
+
</FormField>
|
|
220
|
+
</Fieldset>
|
|
221
|
+
</Box>
|
|
222
|
+
);
|
package/src/Fieldset.tsx
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Box from "@sproutsocial/seeds-react-box";
|
|
3
|
+
import Text from "@sproutsocial/seeds-react-text";
|
|
4
|
+
import { ChildContainer } from "./styles";
|
|
5
|
+
import type {
|
|
6
|
+
TypeFieldsetProps,
|
|
7
|
+
TypeFieldsetLegendProps,
|
|
8
|
+
TypeFieldsetHelperText,
|
|
9
|
+
} from "./FieldsetTypes";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fieldset Component
|
|
13
|
+
*/
|
|
14
|
+
const Fieldset = ({
|
|
15
|
+
layout = "vertical",
|
|
16
|
+
label,
|
|
17
|
+
helperText,
|
|
18
|
+
children,
|
|
19
|
+
...rest
|
|
20
|
+
}: TypeFieldsetProps) => (
|
|
21
|
+
<Box as="fieldset" border="none" p={0} data-qa-fieldset="" {...rest}>
|
|
22
|
+
{typeof label === "string" ? (
|
|
23
|
+
<Fieldset.Legend>{label}</Fieldset.Legend>
|
|
24
|
+
) : (
|
|
25
|
+
label
|
|
26
|
+
)}
|
|
27
|
+
{typeof helperText === "string" ? (
|
|
28
|
+
<Fieldset.HelperText>{helperText}</Fieldset.HelperText>
|
|
29
|
+
) : (
|
|
30
|
+
helperText
|
|
31
|
+
)}
|
|
32
|
+
<Box
|
|
33
|
+
display="flex"
|
|
34
|
+
flexDirection={layout === "vertical" ? "column" : "row"}
|
|
35
|
+
>
|
|
36
|
+
{React.Children.map(children, (child) => (
|
|
37
|
+
<ChildContainer layout={layout}>{child}</ChildContainer>
|
|
38
|
+
))}
|
|
39
|
+
</Box>
|
|
40
|
+
</Box>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const FieldsetLegend = ({ children, ...rest }: TypeFieldsetLegendProps) => (
|
|
44
|
+
<Text
|
|
45
|
+
as="legend"
|
|
46
|
+
fontSize={300}
|
|
47
|
+
fontWeight="semibold"
|
|
48
|
+
color="text.body"
|
|
49
|
+
mb={300}
|
|
50
|
+
{...rest}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
</Text>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const FieldsetHelperText = ({ children, ...rest }: TypeFieldsetHelperText) => (
|
|
57
|
+
<Text as="p" fontSize={200} mb={300} {...rest}>
|
|
58
|
+
{children}
|
|
59
|
+
</Text>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
FieldsetLegend.displayName = "Fieldset.Legend";
|
|
63
|
+
FieldsetHelperText.displayName = "Fieldset.HelperText";
|
|
64
|
+
|
|
65
|
+
Fieldset.Legend = FieldsetLegend;
|
|
66
|
+
Fieldset.HelperText = FieldsetHelperText;
|
|
67
|
+
|
|
68
|
+
export default Fieldset;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TypeTextProps } from "@sproutsocial/seeds-react-text";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { TypeBoxProps } from "@sproutsocial/seeds-react-box";
|
|
4
|
+
|
|
5
|
+
export interface TypeFieldsetProps extends TypeBoxProps {
|
|
6
|
+
/** Label text to display above the fieldset */
|
|
7
|
+
label: React.ReactNode;
|
|
8
|
+
helperText?: React.ReactNode;
|
|
9
|
+
layout?: "vertical" | "horizontal";
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface TypeFieldsetChildContainerProps {
|
|
14
|
+
layout: TypeFieldsetProps["layout"];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TypeFieldsetLegendProps extends TypeTextProps {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TypeFieldsetHelperText extends TypeTextProps {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@sproutsocial/seeds-react-testing-library";
|
|
3
|
+
import Radio from "@sproutsocial/seeds-react-radio";
|
|
4
|
+
import Fieldset from "../Fieldset";
|
|
5
|
+
|
|
6
|
+
test("Fieldset builds component when supplied props", () => {
|
|
7
|
+
render(
|
|
8
|
+
<Fieldset label="the label" helperText="helper text">
|
|
9
|
+
<Radio id="the content" name="the content" label="the content" />
|
|
10
|
+
</Fieldset>
|
|
11
|
+
);
|
|
12
|
+
expect(screen.getByText("the label")).toBeInTheDocument();
|
|
13
|
+
expect(screen.getByText("helper text")).toBeInTheDocument();
|
|
14
|
+
expect(screen.getByLabelText("the content")).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("Fieldset supports custom label and helper text", () => {
|
|
18
|
+
render(
|
|
19
|
+
<Fieldset
|
|
20
|
+
label={<Fieldset.Legend fontSize={500}>the label</Fieldset.Legend>}
|
|
21
|
+
helperText={
|
|
22
|
+
<Fieldset.HelperText mb={400}>helper text</Fieldset.HelperText>
|
|
23
|
+
}
|
|
24
|
+
>
|
|
25
|
+
<Radio id="the content" name="the content" label="the content" />
|
|
26
|
+
</Fieldset>
|
|
27
|
+
);
|
|
28
|
+
expect(screen.getByText("the label")).toBeInTheDocument();
|
|
29
|
+
expect(screen.getByText("helper text")).toBeInTheDocument();
|
|
30
|
+
expect(screen.getByLabelText("the content")).toBeInTheDocument();
|
|
31
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Radio from "@sproutsocial/seeds-react-radio";
|
|
3
|
+
import Fieldset from "../Fieldset";
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
function FieldsetTypes() {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Fieldset label="the label" helperText="helper text">
|
|
10
|
+
<Radio id="the content" name="the content" label="the content" />
|
|
11
|
+
</Fieldset>
|
|
12
|
+
<Fieldset
|
|
13
|
+
label={<Fieldset.Legend fontSize={500}>the label</Fieldset.Legend>}
|
|
14
|
+
helperText={
|
|
15
|
+
<Fieldset.HelperText mb={400}>helper text</Fieldset.HelperText>
|
|
16
|
+
}
|
|
17
|
+
>
|
|
18
|
+
<Radio id="the content" name="the content" label="the content" />
|
|
19
|
+
</Fieldset>
|
|
20
|
+
|
|
21
|
+
{/* @ts-expect-error - test that invalid type is rejected */}
|
|
22
|
+
<Fieldset>{/* empty */}</Fieldset>
|
|
23
|
+
|
|
24
|
+
{/* @ts-expect-error - test that invalid type is rejected */}
|
|
25
|
+
<Fieldset>
|
|
26
|
+
<div>thing</div>
|
|
27
|
+
</Fieldset>
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
}
|
package/src/index.ts
ADDED
package/src/styled.d.ts
ADDED
package/src/styles.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
import type { TypeFieldsetChildContainerProps } from "./FieldsetTypes";
|
|
3
|
+
import Box from "@sproutsocial/seeds-react-box";
|
|
4
|
+
|
|
5
|
+
export const ChildContainer = styled(Box)<TypeFieldsetChildContainerProps>`
|
|
6
|
+
${(props) =>
|
|
7
|
+
props.layout === "vertical" &&
|
|
8
|
+
css`
|
|
9
|
+
margin-top: ${props.theme.space[300]};
|
|
10
|
+
|
|
11
|
+
&:first-child {
|
|
12
|
+
margin-top: 0;
|
|
13
|
+
}
|
|
14
|
+
`}
|
|
15
|
+
|
|
16
|
+
${(props) =>
|
|
17
|
+
props.layout === "horizontal" &&
|
|
18
|
+
css`
|
|
19
|
+
margin-left: ${props.theme.space[300]};
|
|
20
|
+
|
|
21
|
+
&:first-child {
|
|
22
|
+
margin-left: 0;
|
|
23
|
+
}
|
|
24
|
+
`}
|
|
25
|
+
`;
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options) => ({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"],
|
|
6
|
+
clean: true,
|
|
7
|
+
legacyOutput: true,
|
|
8
|
+
dts: options.dts,
|
|
9
|
+
external: ["react"],
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
metafile: options.metafile,
|
|
12
|
+
}));
|