@sproutsocial/seeds-react-loader-button 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 ADDED
@@ -0,0 +1,6 @@
1
+ # Node modules
2
+ node_modules/
3
+
4
+ # Build output
5
+ dist/
6
+ coverage/
package/.eslintrc.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ["eslint-config-seeds/racine"],
4
+ };
@@ -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-loader-button/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 3.61 KB
12
+ CJS dist/index.js.map 3.09 KB
13
+ CJS ⚡️ Build success in 202ms
14
+ ESM dist/esm/index.js 1.62 KB
15
+ ESM dist/esm/index.js.map 2.96 KB
16
+ ESM ⚡️ Build success in 203ms
17
+ DTS Build start
18
+ DTS ⚡️ Build success in 27350ms
19
+ DTS dist/index.d.ts 470.00 B
20
+ DTS dist/index.d.mts 470.00 B
21
+ Done in 32.92s.
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @sproutsocial/seeds-react-loader-button
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - cf814f5: Migrate LoaderButton to its own seeds-react-loader-button package
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [f985353]
12
+ - @sproutsocial/seeds-react-loader@1.0.0
@@ -0,0 +1,46 @@
1
+ // src/LoaderButton.tsx
2
+ import "react";
3
+ import styled from "styled-components";
4
+ import Box from "@sproutsocial/seeds-react-box";
5
+ import Button from "@sproutsocial/seeds-react-button";
6
+ import Loader from "@sproutsocial/seeds-react-loader";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ var StyledLoaderButton = styled(Button)`
9
+ background-color: ${({ theme, appearance, disabled }) => {
10
+ const buttonBackgroundColor = theme.colors.button[appearance]?.background?.base;
11
+ const isBackgroundColorTransparent = buttonBackgroundColor === "transparent";
12
+ return disabled ? isBackgroundColorTransparent ? "transparent" : `${buttonBackgroundColor}66` : buttonBackgroundColor;
13
+ }};
14
+ ${({ disabled }) => disabled && "opacity: 1;"}
15
+ `;
16
+ var LoaderButton = ({
17
+ isLoading = false,
18
+ disabled,
19
+ loaderLabel,
20
+ children,
21
+ appearance = "unstyled",
22
+ ...rest
23
+ }) => {
24
+ return /* @__PURE__ */ jsx(
25
+ StyledLoaderButton,
26
+ {
27
+ disabled: disabled || isLoading,
28
+ appearance,
29
+ "data-qa-button-isloading": isLoading === true,
30
+ ...rest,
31
+ children: /* @__PURE__ */ jsxs(Box, { position: "relative", children: [
32
+ /* @__PURE__ */ jsx(Box, { opacity: isLoading ? 0 : 1, "aria-hidden": isLoading, children }),
33
+ isLoading && /* @__PURE__ */ jsx(Box, { position: "absolute", top: -2, left: 0, right: 0, bottom: 0, children: /* @__PURE__ */ jsx(Loader, { text: loaderLabel, size: "small", delay: false }) })
34
+ ] })
35
+ }
36
+ );
37
+ };
38
+ var LoaderButton_default = LoaderButton;
39
+
40
+ // src/index.ts
41
+ var src_default = LoaderButton_default;
42
+ export {
43
+ LoaderButton_default as LoaderButton,
44
+ src_default as default
45
+ };
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/LoaderButton.tsx","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport styled from \"styled-components\";\nimport Box from \"@sproutsocial/seeds-react-box\";\nimport Button from \"@sproutsocial/seeds-react-button\";\nimport Loader from \"@sproutsocial/seeds-react-loader\";\nimport type { TypeLoaderButtonProps } from \"./LoaderButtonTypes\";\n\nconst StyledLoaderButton = styled(Button)`\n background-color: ${({ theme, appearance, disabled }) => {\n const buttonBackgroundColor =\n theme.colors.button[appearance as keyof typeof theme.colors.button]\n ?.background?.base;\n\n const isBackgroundColorTransparent =\n buttonBackgroundColor === \"transparent\";\n\n // If the button is disabled we want to check what the buttonBackgroundColor is, if it is transparent we want to return transparent, otherwise we want to return the buttonBackgroundColor with an opacity of 0.4. If the button is not disabled we want to return the buttonBackgroundColor.\n return disabled\n ? isBackgroundColorTransparent\n ? \"transparent\"\n : `${buttonBackgroundColor}66`\n : buttonBackgroundColor;\n }};\n ${({ disabled }) => disabled && \"opacity: 1;\"}\n`;\n\nexport const LoaderButton = ({\n isLoading = false,\n disabled,\n loaderLabel,\n children,\n appearance = \"unstyled\",\n ...rest\n}: TypeLoaderButtonProps) => {\n return (\n <StyledLoaderButton\n disabled={disabled || isLoading}\n appearance={appearance}\n data-qa-button-isloading={isLoading === true}\n {...rest}\n >\n <Box position=\"relative\">\n <Box opacity={isLoading ? 0 : 1} aria-hidden={isLoading}>\n {children}\n </Box>\n {isLoading && (\n <Box position=\"absolute\" top={-2} left={0} right={0} bottom={0}>\n <Loader text={loaderLabel} size=\"small\" delay={false} />\n </Box>\n )}\n </Box>\n </StyledLoaderButton>\n );\n};\n\nexport default LoaderButton;\n","import LoaderButton from \"./LoaderButton\";\n\nexport default LoaderButton;\nexport { LoaderButton };\nexport * from \"./LoaderButtonTypes\";\n"],"mappings":";AAAA,OAAuB;AACvB,OAAO,YAAY;AACnB,OAAO,SAAS;AAChB,OAAO,YAAY;AACnB,OAAO,YAAY;AAqCb,SACE,KADF;AAlCN,IAAM,qBAAqB,OAAO,MAAM;AAAA,sBAClB,CAAC,EAAE,OAAO,YAAY,SAAS,MAAM;AACvD,QAAM,wBACJ,MAAM,OAAO,OAAO,UAA8C,GAC9D,YAAY;AAElB,QAAM,+BACJ,0BAA0B;AAG5B,SAAO,WACH,+BACE,gBACA,GAAG,qBAAqB,OAC1B;AACN,CAAC;AAAA,IACC,CAAC,EAAE,SAAS,MAAM,YAAY,aAAa;AAAA;AAGxC,IAAM,eAAe,CAAC;AAAA,EAC3B,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,GAAG;AACL,MAA6B;AAC3B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB;AAAA,MACA,4BAA0B,cAAc;AAAA,MACvC,GAAG;AAAA,MAEJ,+BAAC,OAAI,UAAS,YACZ;AAAA,4BAAC,OAAI,SAAS,YAAY,IAAI,GAAG,eAAa,WAC3C,UACH;AAAA,QACC,aACC,oBAAC,OAAI,UAAS,YAAW,KAAK,IAAI,MAAM,GAAG,OAAO,GAAG,QAAQ,GAC3D,8BAAC,UAAO,MAAM,aAAa,MAAK,SAAQ,OAAO,OAAO,GACxD;AAAA,SAEJ;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,uBAAQ;;;ACrDf,IAAO,cAAQ;","names":[]}
@@ -0,0 +1,11 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { TypeButtonProps } from '@sproutsocial/seeds-react-button';
3
+
4
+ interface TypeLoaderButtonProps extends TypeButtonProps {
5
+ isLoading?: boolean;
6
+ loaderLabel: string;
7
+ }
8
+
9
+ declare const LoaderButton: ({ isLoading, disabled, loaderLabel, children, appearance, ...rest }: TypeLoaderButtonProps) => react_jsx_runtime.JSX.Element;
10
+
11
+ export { LoaderButton, type TypeLoaderButtonProps, LoaderButton as default };
@@ -0,0 +1,11 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { TypeButtonProps } from '@sproutsocial/seeds-react-button';
3
+
4
+ interface TypeLoaderButtonProps extends TypeButtonProps {
5
+ isLoading?: boolean;
6
+ loaderLabel: string;
7
+ }
8
+
9
+ declare const LoaderButton: ({ isLoading, disabled, loaderLabel, children, appearance, ...rest }: TypeLoaderButtonProps) => react_jsx_runtime.JSX.Element;
10
+
11
+ export { LoaderButton, type TypeLoaderButtonProps, LoaderButton as default };
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
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
+ LoaderButton: () => LoaderButton_default,
34
+ default: () => src_default
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/LoaderButton.tsx
39
+ var React = require("react");
40
+ var import_styled_components = __toESM(require("styled-components"));
41
+ var import_seeds_react_box = __toESM(require("@sproutsocial/seeds-react-box"));
42
+ var import_seeds_react_button = __toESM(require("@sproutsocial/seeds-react-button"));
43
+ var import_seeds_react_loader = __toESM(require("@sproutsocial/seeds-react-loader"));
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ var StyledLoaderButton = (0, import_styled_components.default)(import_seeds_react_button.default)`
46
+ background-color: ${({ theme, appearance, disabled }) => {
47
+ const buttonBackgroundColor = theme.colors.button[appearance]?.background?.base;
48
+ const isBackgroundColorTransparent = buttonBackgroundColor === "transparent";
49
+ return disabled ? isBackgroundColorTransparent ? "transparent" : `${buttonBackgroundColor}66` : buttonBackgroundColor;
50
+ }};
51
+ ${({ disabled }) => disabled && "opacity: 1;"}
52
+ `;
53
+ var LoaderButton = ({
54
+ isLoading = false,
55
+ disabled,
56
+ loaderLabel,
57
+ children,
58
+ appearance = "unstyled",
59
+ ...rest
60
+ }) => {
61
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
62
+ StyledLoaderButton,
63
+ {
64
+ disabled: disabled || isLoading,
65
+ appearance,
66
+ "data-qa-button-isloading": isLoading === true,
67
+ ...rest,
68
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_seeds_react_box.default, { position: "relative", children: [
69
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_seeds_react_box.default, { opacity: isLoading ? 0 : 1, "aria-hidden": isLoading, children }),
70
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_seeds_react_box.default, { position: "absolute", top: -2, left: 0, right: 0, bottom: 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_seeds_react_loader.default, { text: loaderLabel, size: "small", delay: false }) })
71
+ ] })
72
+ }
73
+ );
74
+ };
75
+ var LoaderButton_default = LoaderButton;
76
+
77
+ // src/index.ts
78
+ var src_default = LoaderButton_default;
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ LoaderButton
82
+ });
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/LoaderButton.tsx"],"sourcesContent":["import LoaderButton from \"./LoaderButton\";\n\nexport default LoaderButton;\nexport { LoaderButton };\nexport * from \"./LoaderButtonTypes\";\n","import * as React from \"react\";\nimport styled from \"styled-components\";\nimport Box from \"@sproutsocial/seeds-react-box\";\nimport Button from \"@sproutsocial/seeds-react-button\";\nimport Loader from \"@sproutsocial/seeds-react-loader\";\nimport type { TypeLoaderButtonProps } from \"./LoaderButtonTypes\";\n\nconst StyledLoaderButton = styled(Button)`\n background-color: ${({ theme, appearance, disabled }) => {\n const buttonBackgroundColor =\n theme.colors.button[appearance as keyof typeof theme.colors.button]\n ?.background?.base;\n\n const isBackgroundColorTransparent =\n buttonBackgroundColor === \"transparent\";\n\n // If the button is disabled we want to check what the buttonBackgroundColor is, if it is transparent we want to return transparent, otherwise we want to return the buttonBackgroundColor with an opacity of 0.4. If the button is not disabled we want to return the buttonBackgroundColor.\n return disabled\n ? isBackgroundColorTransparent\n ? \"transparent\"\n : `${buttonBackgroundColor}66`\n : buttonBackgroundColor;\n }};\n ${({ disabled }) => disabled && \"opacity: 1;\"}\n`;\n\nexport const LoaderButton = ({\n isLoading = false,\n disabled,\n loaderLabel,\n children,\n appearance = \"unstyled\",\n ...rest\n}: TypeLoaderButtonProps) => {\n return (\n <StyledLoaderButton\n disabled={disabled || isLoading}\n appearance={appearance}\n data-qa-button-isloading={isLoading === true}\n {...rest}\n >\n <Box position=\"relative\">\n <Box opacity={isLoading ? 0 : 1} aria-hidden={isLoading}>\n {children}\n </Box>\n {isLoading && (\n <Box position=\"absolute\" top={-2} left={0} right={0} bottom={0}>\n <Loader text={loaderLabel} size=\"small\" delay={false} />\n </Box>\n )}\n </Box>\n </StyledLoaderButton>\n );\n};\n\nexport default LoaderButton;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,+BAAmB;AACnB,6BAAgB;AAChB,gCAAmB;AACnB,gCAAmB;AAqCb;AAlCN,IAAM,yBAAqB,yBAAAA,SAAO,0BAAAC,OAAM;AAAA,sBAClB,CAAC,EAAE,OAAO,YAAY,SAAS,MAAM;AACvD,QAAM,wBACJ,MAAM,OAAO,OAAO,UAA8C,GAC9D,YAAY;AAElB,QAAM,+BACJ,0BAA0B;AAG5B,SAAO,WACH,+BACE,gBACA,GAAG,qBAAqB,OAC1B;AACN,CAAC;AAAA,IACC,CAAC,EAAE,SAAS,MAAM,YAAY,aAAa;AAAA;AAGxC,IAAM,eAAe,CAAC;AAAA,EAC3B,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,GAAG;AACL,MAA6B;AAC3B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,YAAY;AAAA,MACtB;AAAA,MACA,4BAA0B,cAAc;AAAA,MACvC,GAAG;AAAA,MAEJ,uDAAC,uBAAAC,SAAA,EAAI,UAAS,YACZ;AAAA,oDAAC,uBAAAA,SAAA,EAAI,SAAS,YAAY,IAAI,GAAG,eAAa,WAC3C,UACH;AAAA,QACC,aACC,4CAAC,uBAAAA,SAAA,EAAI,UAAS,YAAW,KAAK,IAAI,MAAM,GAAG,OAAO,GAAG,QAAQ,GAC3D,sDAAC,0BAAAC,SAAA,EAAO,MAAM,aAAa,MAAK,SAAQ,OAAO,OAAO,GACxD;AAAA,SAEJ;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,uBAAQ;;;ADrDf,IAAO,cAAQ;","names":["styled","Button","Box","Loader"]}
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ const baseConfig = require("@sproutsocial/seeds-testing");
2
+
3
+ /** * @type {import('jest').Config} */
4
+ const config = {
5
+ ...baseConfig,
6
+ displayName: "seeds-react-loader-button",
7
+ };
8
+
9
+ module.exports = config;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@sproutsocial/seeds-react-loader-button",
3
+ "version": "1.0.0",
4
+ "description": "Seeds React LoaderButton",
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-button": "*",
25
+ "@sproutsocial/seeds-react-loader": "*"
26
+ },
27
+ "devDependencies": {
28
+ "@types/react": "^18.0.0",
29
+ "@types/styled-components": "^5.1.26",
30
+ "@sproutsocial/eslint-config-seeds": "*",
31
+ "react": "^18.0.0",
32
+ "styled-components": "^5.2.3",
33
+ "tsup": "^8.0.2",
34
+ "typescript": "^5.6.2",
35
+ "@sproutsocial/seeds-tsconfig": "*",
36
+ "@sproutsocial/seeds-testing": "*",
37
+ "@sproutsocial/seeds-react-testing-library": "*"
38
+ },
39
+ "peerDependencies": {
40
+ "styled-components": "^5.2.3"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ }
45
+ }
@@ -0,0 +1,79 @@
1
+ import React from "react";
2
+ import type { Meta, StoryObj } from "@storybook/react";
3
+ import Box from "@sproutsocial/seeds-react-box";
4
+ import LoaderButton from "./LoaderButton";
5
+
6
+ const meta: Meta<typeof LoaderButton> = {
7
+ title: "Components/LoaderButton",
8
+ component: LoaderButton,
9
+ };
10
+ export default meta;
11
+
12
+ type Story = StoryObj<typeof LoaderButton>;
13
+
14
+ export const Default: Story = {
15
+ render: () => (
16
+ <Box>
17
+ <LoaderButton mb={400} loaderLabel="Loading...">
18
+ Not loading (yet)
19
+ </LoaderButton>
20
+ <br />
21
+ <LoaderButton isLoading loaderLabel="Loading...">
22
+ Not loading (yet)
23
+ </LoaderButton>
24
+ </Box>
25
+ ),
26
+ };
27
+
28
+ export const Primary: Story = {
29
+ render: () => (
30
+ <Box>
31
+ <LoaderButton appearance="primary" mb={400} loaderLabel="Loading...">
32
+ Not loading (yet)
33
+ </LoaderButton>
34
+ <br />
35
+ <LoaderButton appearance="primary" isLoading loaderLabel="Loading...">
36
+ Not loading (yet)
37
+ </LoaderButton>
38
+ </Box>
39
+ ),
40
+ };
41
+
42
+ export const Secondary: Story = {
43
+ render: () => (
44
+ <Box>
45
+ <LoaderButton appearance="secondary" mb={400} loaderLabel="Loading...">
46
+ Not loading (yet)
47
+ </LoaderButton>
48
+ <br />
49
+ <LoaderButton appearance="secondary" isLoading loaderLabel="Loading...">
50
+ Not loading (yet)
51
+ </LoaderButton>
52
+ </Box>
53
+ ),
54
+ };
55
+
56
+ export const AllLoaderButtons: Story = {
57
+ render: () => (
58
+ <Box display="flex" justifyContent="space-around">
59
+ <LoaderButton isLoading loaderLabel="Loading...">
60
+ Loading Button
61
+ </LoaderButton>
62
+ <LoaderButton appearance="primary" isLoading loaderLabel="Loading...">
63
+ Loading Button
64
+ </LoaderButton>
65
+ <LoaderButton appearance="secondary" isLoading loaderLabel="Loading...">
66
+ Loading Button
67
+ </LoaderButton>
68
+ <LoaderButton appearance="destructive" isLoading loaderLabel="Loading...">
69
+ Loading Button
70
+ </LoaderButton>
71
+ <LoaderButton appearance="placeholder" isLoading loaderLabel="Loading...">
72
+ Loading Button
73
+ </LoaderButton>
74
+ <LoaderButton appearance="pill" isLoading loaderLabel="Loading...">
75
+ Loading Button
76
+ </LoaderButton>
77
+ </Box>
78
+ ),
79
+ };
@@ -0,0 +1,56 @@
1
+ import * as React from "react";
2
+ import styled from "styled-components";
3
+ import Box from "@sproutsocial/seeds-react-box";
4
+ import Button from "@sproutsocial/seeds-react-button";
5
+ import Loader from "@sproutsocial/seeds-react-loader";
6
+ import type { TypeLoaderButtonProps } from "./LoaderButtonTypes";
7
+
8
+ const StyledLoaderButton = styled(Button)`
9
+ background-color: ${({ theme, appearance, disabled }) => {
10
+ const buttonBackgroundColor =
11
+ theme.colors.button[appearance as keyof typeof theme.colors.button]
12
+ ?.background?.base;
13
+
14
+ const isBackgroundColorTransparent =
15
+ buttonBackgroundColor === "transparent";
16
+
17
+ // If the button is disabled we want to check what the buttonBackgroundColor is, if it is transparent we want to return transparent, otherwise we want to return the buttonBackgroundColor with an opacity of 0.4. If the button is not disabled we want to return the buttonBackgroundColor.
18
+ return disabled
19
+ ? isBackgroundColorTransparent
20
+ ? "transparent"
21
+ : `${buttonBackgroundColor}66`
22
+ : buttonBackgroundColor;
23
+ }};
24
+ ${({ disabled }) => disabled && "opacity: 1;"}
25
+ `;
26
+
27
+ export const LoaderButton = ({
28
+ isLoading = false,
29
+ disabled,
30
+ loaderLabel,
31
+ children,
32
+ appearance = "unstyled",
33
+ ...rest
34
+ }: TypeLoaderButtonProps) => {
35
+ return (
36
+ <StyledLoaderButton
37
+ disabled={disabled || isLoading}
38
+ appearance={appearance}
39
+ data-qa-button-isloading={isLoading === true}
40
+ {...rest}
41
+ >
42
+ <Box position="relative">
43
+ <Box opacity={isLoading ? 0 : 1} aria-hidden={isLoading}>
44
+ {children}
45
+ </Box>
46
+ {isLoading && (
47
+ <Box position="absolute" top={-2} left={0} right={0} bottom={0}>
48
+ <Loader text={loaderLabel} size="small" delay={false} />
49
+ </Box>
50
+ )}
51
+ </Box>
52
+ </StyledLoaderButton>
53
+ );
54
+ };
55
+
56
+ export default LoaderButton;
@@ -0,0 +1,6 @@
1
+ import type { TypeButtonProps } from "@sproutsocial/seeds-react-button";
2
+
3
+ export interface TypeLoaderButtonProps extends TypeButtonProps {
4
+ isLoading?: boolean;
5
+ loaderLabel: string;
6
+ }
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import { render, screen } from "@sproutsocial/seeds-react-testing-library";
3
+ import LoaderButton from "../LoaderButton";
4
+
5
+ describe("LoaderButton", () => {
6
+ it("should render properly", async () => {
7
+ const { container, runA11yCheck } = render(
8
+ <LoaderButton loaderLabel="loading">LoaderButton</LoaderButton>
9
+ );
10
+
11
+ expect(container).toBeTruthy();
12
+ await runA11yCheck();
13
+ });
14
+
15
+ it("should show the loader", async () => {
16
+ const { rerender } = render(
17
+ <LoaderButton loaderLabel="loading">text</LoaderButton>
18
+ );
19
+ let loader = screen.queryByText("loading");
20
+ let loaderButton = screen.queryByText("text");
21
+
22
+ expect(loader).not.toBeInTheDocument();
23
+ expect(loaderButton).toHaveAttribute("aria-hidden", "false");
24
+
25
+ rerender(
26
+ <LoaderButton isLoading loaderLabel="loading">
27
+ text
28
+ </LoaderButton>
29
+ );
30
+
31
+ loader = screen.queryByText("loading");
32
+ loaderButton = screen.queryByText("text");
33
+
34
+ expect(loader).toBeInTheDocument();
35
+ expect(loaderButton).toHaveAttribute("aria-hidden", "true");
36
+ });
37
+ });
@@ -0,0 +1,36 @@
1
+ import * as React from "react";
2
+ import LoaderButton from "../LoaderButton";
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ function LoaderButtonTypes() {
6
+ return (
7
+ <>
8
+ <LoaderButton appearance="primary" mb={400} loaderLabel="Loading...">
9
+ Not loading (yet)
10
+ </LoaderButton>
11
+ <LoaderButton appearance="secondary" mb={400} loaderLabel="Loading...">
12
+ Not loading (yet)
13
+ </LoaderButton>
14
+ <LoaderButton isLoading loaderLabel="Loading...">
15
+ Loading Button
16
+ </LoaderButton>
17
+ <LoaderButton appearance="primary" isLoading loaderLabel="Loading...">
18
+ Loading Button
19
+ </LoaderButton>
20
+ <LoaderButton appearance="secondary" isLoading loaderLabel="Loading...">
21
+ Loading Button
22
+ </LoaderButton>
23
+ <LoaderButton appearance="destructive" isLoading loaderLabel="Loading...">
24
+ Loading Button
25
+ </LoaderButton>
26
+ <LoaderButton appearance="placeholder" isLoading loaderLabel="Loading...">
27
+ Loading Button
28
+ </LoaderButton>
29
+ <LoaderButton appearance="pill" isLoading loaderLabel="Loading...">
30
+ Loading Button
31
+ </LoaderButton>
32
+ {/* @ts-expect-error - test that missing required props is rejected */}
33
+ <LoaderButton />
34
+ </>
35
+ );
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ import LoaderButton from "./LoaderButton";
2
+
3
+ export default LoaderButton;
4
+ export { LoaderButton };
5
+ export * from "./LoaderButtonTypes";
@@ -0,0 +1,7 @@
1
+ import "styled-components";
2
+ import { TypeTheme } from "@sproutsocial/seeds-react-theme";
3
+
4
+ declare module "styled-components" {
5
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
6
+ export interface DefaultTheme extends TypeTheme {}
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@sproutsocial/seeds-tsconfig/bundler/dom/library-monorepo",
3
+ "compilerOptions": {
4
+ "jsx": "react-jsx",
5
+ "module": "esnext"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "dist", "coverage"]
9
+ }
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
+ }));