@dt-dds/react-icon-button 1.0.0-beta.10

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/CHANGELOG.md ADDED
@@ -0,0 +1,90 @@
1
+ # @dt-ui/react-icon-button
2
+
3
+ ## 1.0.0-beta.10
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: add new themes package
8
+
9
+ ### Patch Changes
10
+
11
+ - chore: update imports and deps
12
+ - chore: rebase with main branch
13
+ - Updated dependencies
14
+ - Updated dependencies
15
+ - Updated dependencies
16
+ - @dt-dds/react-core@1.0.0-beta.42
17
+
18
+ ## 1.0.0-beta.9
19
+
20
+ ### Major Changes
21
+
22
+ - refactor!: rename pkg and publish to npmjs
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+ - @dt-dds/react-core@1.0.0-beta.41
28
+
29
+ ## 0.1.0-beta.8
30
+
31
+ ### Patch Changes
32
+
33
+ - refactor: theme typography values
34
+ - Updated dependencies
35
+ - @dt-ui/react-core@0.1.0-beta.40
36
+
37
+ ## 0.1.0-beta.7
38
+
39
+ ### Minor Changes
40
+
41
+ - feat: update shadow theme values
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies
46
+ - @dt-ui/react-core@0.1.0-beta.39
47
+
48
+ ## 0.1.0-beta.6
49
+
50
+ ### Patch Changes
51
+
52
+ - chore: update theme font-styles
53
+ - Updated dependencies
54
+ - @dt-ui/react-core@0.1.0-beta.38
55
+
56
+ ## 0.1.0-beta.5
57
+
58
+ ### Patch Changes
59
+
60
+ - chore: review OSS files
61
+ - Updated dependencies
62
+ - @dt-ui/react-core@0.1.0-beta.37
63
+
64
+ ## 0.1.0-beta.4
65
+
66
+ ### Patch Changes
67
+
68
+ - chore: update contextual colors
69
+ - Updated dependencies
70
+ - @dt-ui/react-core@0.1.0-beta.36
71
+
72
+ ## 0.1.0-beta.3
73
+
74
+ ### Minor Changes
75
+
76
+ - feat: implement IconButton contrast and size
77
+
78
+ ## 0.1.0-beta.2
79
+
80
+ ### Patch Changes
81
+
82
+ - fix: change content.light contextual color
83
+ - Updated dependencies
84
+ - @dt-ui/react-core@0.1.0-beta.35
85
+
86
+ ## 0.1.0-beta.1
87
+
88
+ ### Minor Changes
89
+
90
+ - feat: move icon-button to independent
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daimler Truck AG.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # IconButton
2
+
3
+ This component allows the user to take action by clicking on an Icon.
4
+
5
+ ## Usage
6
+
7
+ ```jsx
8
+ import { IconButton, EditIcon } from '@dt-dds/react';
9
+
10
+ export const App = () => {
11
+ const handleClick = () => null;
12
+
13
+ return (
14
+ <IconButton onClick={handleClick}>
15
+ <EditIcon />
16
+ </IconButton>
17
+ );
18
+ };
19
+ ```
20
+
21
+ ## API
22
+
23
+ ### IconButton
24
+
25
+ | Property | Type | Default | Description |
26
+ | ------------ | ------------------- | --------- | ------------------------------------------------- |
27
+ | `children` | `ReactNode` | - | Icon component to be rendered |
28
+ | `onClick` | `function` | - | The triggered function when clicked on the button |
29
+ | `dataTestId` | `string` | button | Customizable test identifier |
30
+ | `isDisabled` | `boolean` | false | Determines the disabled state of the button |
31
+ | `variant` | `IconButtonVariant` | `default` | Determines the variant of the icon |
32
+ | `size` | `ComponentSize` | `large` | Determines the size of the icon |
33
+
34
+ ## &copy; License
35
+
36
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,22 @@
1
+ import { CustomTheme } from '@dt-dds/themes';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { BaseProps, ComponentSize } from '@dt-dds/react-core';
4
+ import { ComponentPropsWithoutRef } from 'react';
5
+
6
+ type IconButtonVariant = 'contrast' | 'default';
7
+
8
+ interface IconButtonProps extends ComponentPropsWithoutRef<'button'>, BaseProps {
9
+ onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
10
+ isDisabled?: boolean;
11
+ ariaLabel?: string;
12
+ variant?: IconButtonVariant;
13
+ size?: ComponentSize;
14
+ }
15
+ declare const IconButton: ({ children, dataTestId, isDisabled, ariaLabel, variant, size, onClick, ...props }: IconButtonProps) => react_jsx_runtime.JSX.Element;
16
+
17
+ declare module '@emotion/react' {
18
+ interface Theme extends CustomTheme {
19
+ }
20
+ }
21
+
22
+ export { IconButton, IconButtonProps };
package/dist/index.js ADDED
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+
59
+ // index.ts
60
+ var icon_button_exports = {};
61
+ __export(icon_button_exports, {
62
+ IconButton: () => IconButton
63
+ });
64
+ module.exports = __toCommonJS(icon_button_exports);
65
+
66
+ // src/IconButton.styled.ts
67
+ var import_styled = __toESM(require("@emotion/styled"));
68
+ var iconButtonSizeStyles = {
69
+ "extra-small": `
70
+ font-size: 12px;
71
+ `,
72
+ small: `
73
+ font-size: 16px;
74
+ `,
75
+ medium: `
76
+ font-size: 20px;
77
+ `,
78
+ large: `
79
+ font-size: 24px;
80
+ `,
81
+ "extra-large": `
82
+ font-size: 32px;
83
+ `
84
+ };
85
+ var IconButtonStyled = import_styled.default.button(
86
+ ({ theme, disabled, variant = "default", size = "large" }) => {
87
+ const isDefaultVariant = variant === "default";
88
+ const baseColor = () => {
89
+ if (disabled) {
90
+ return isDefaultVariant ? theme.palette.content.light : theme.palette.content.default;
91
+ }
92
+ return isDefaultVariant ? theme.palette.content.default : theme.palette.content.contrast;
93
+ };
94
+ const hoverColor = isDefaultVariant ? theme.palette.accent.default : theme.palette.accent.medium;
95
+ return `
96
+ display: flex;
97
+ align-items: center;
98
+ border: none;
99
+ background-color: transparent;
100
+ cursor: ${disabled ? "not-allowed" : "pointer"};
101
+
102
+ i {
103
+ ${iconButtonSizeStyles[size]};
104
+ color: ${baseColor()};
105
+ }
106
+
107
+ &:not(:disabled) > i {
108
+ &:hover, &:active {
109
+ color: ${hoverColor};
110
+ }
111
+ }
112
+
113
+ &:focus-visible {
114
+ outline: 2px solid ${theme.palette.primary.default};
115
+ }
116
+ `;
117
+ }
118
+ );
119
+
120
+ // src/IconButton.tsx
121
+ var import_jsx_runtime = require("react/jsx-runtime");
122
+ var IconButton = (_a) => {
123
+ var _b = _a, {
124
+ children,
125
+ dataTestId,
126
+ isDisabled,
127
+ ariaLabel,
128
+ variant,
129
+ size,
130
+ onClick
131
+ } = _b, props = __objRest(_b, [
132
+ "children",
133
+ "dataTestId",
134
+ "isDisabled",
135
+ "ariaLabel",
136
+ "variant",
137
+ "size",
138
+ "onClick"
139
+ ]);
140
+ const handleClick = (e) => {
141
+ if (isDisabled) {
142
+ return;
143
+ }
144
+ e.preventDefault();
145
+ e.stopPropagation();
146
+ onClick && onClick(e);
147
+ };
148
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
149
+ IconButtonStyled,
150
+ __spreadProps(__spreadValues({
151
+ "aria-label": ariaLabel,
152
+ "data-testid": dataTestId ? dataTestId : "icon-button",
153
+ disabled: isDisabled,
154
+ onClick: handleClick,
155
+ size,
156
+ variant
157
+ }, props), {
158
+ children
159
+ })
160
+ );
161
+ };
162
+ // Annotate the CommonJS export names for ESM import in node:
163
+ 0 && (module.exports = {
164
+ IconButton
165
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,131 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/IconButton.styled.ts
34
+ import styled from "@emotion/styled";
35
+ var iconButtonSizeStyles = {
36
+ "extra-small": `
37
+ font-size: 12px;
38
+ `,
39
+ small: `
40
+ font-size: 16px;
41
+ `,
42
+ medium: `
43
+ font-size: 20px;
44
+ `,
45
+ large: `
46
+ font-size: 24px;
47
+ `,
48
+ "extra-large": `
49
+ font-size: 32px;
50
+ `
51
+ };
52
+ var IconButtonStyled = styled.button(
53
+ ({ theme, disabled, variant = "default", size = "large" }) => {
54
+ const isDefaultVariant = variant === "default";
55
+ const baseColor = () => {
56
+ if (disabled) {
57
+ return isDefaultVariant ? theme.palette.content.light : theme.palette.content.default;
58
+ }
59
+ return isDefaultVariant ? theme.palette.content.default : theme.palette.content.contrast;
60
+ };
61
+ const hoverColor = isDefaultVariant ? theme.palette.accent.default : theme.palette.accent.medium;
62
+ return `
63
+ display: flex;
64
+ align-items: center;
65
+ border: none;
66
+ background-color: transparent;
67
+ cursor: ${disabled ? "not-allowed" : "pointer"};
68
+
69
+ i {
70
+ ${iconButtonSizeStyles[size]};
71
+ color: ${baseColor()};
72
+ }
73
+
74
+ &:not(:disabled) > i {
75
+ &:hover, &:active {
76
+ color: ${hoverColor};
77
+ }
78
+ }
79
+
80
+ &:focus-visible {
81
+ outline: 2px solid ${theme.palette.primary.default};
82
+ }
83
+ `;
84
+ }
85
+ );
86
+
87
+ // src/IconButton.tsx
88
+ import { jsx } from "react/jsx-runtime";
89
+ var IconButton = (_a) => {
90
+ var _b = _a, {
91
+ children,
92
+ dataTestId,
93
+ isDisabled,
94
+ ariaLabel,
95
+ variant,
96
+ size,
97
+ onClick
98
+ } = _b, props = __objRest(_b, [
99
+ "children",
100
+ "dataTestId",
101
+ "isDisabled",
102
+ "ariaLabel",
103
+ "variant",
104
+ "size",
105
+ "onClick"
106
+ ]);
107
+ const handleClick = (e) => {
108
+ if (isDisabled) {
109
+ return;
110
+ }
111
+ e.preventDefault();
112
+ e.stopPropagation();
113
+ onClick && onClick(e);
114
+ };
115
+ return /* @__PURE__ */ jsx(
116
+ IconButtonStyled,
117
+ __spreadProps(__spreadValues({
118
+ "aria-label": ariaLabel,
119
+ "data-testid": dataTestId ? dataTestId : "icon-button",
120
+ disabled: isDisabled,
121
+ onClick: handleClick,
122
+ size,
123
+ variant
124
+ }, props), {
125
+ children
126
+ })
127
+ );
128
+ };
129
+ export {
130
+ IconButton
131
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@dt-dds/react-icon-button",
3
+ "version": "1.0.0-beta.10",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": "./dist/index.js"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist/**"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsup --watch",
17
+ "lint": "eslint --cache .",
18
+ "test": "jest",
19
+ "test:report": "open ./jest-coverage/lcov-report/index.html",
20
+ "test:update:snapshot": "jest -u"
21
+ },
22
+ "dependencies": {
23
+ "@dt-dds/react-core": "1.0.0-beta.42"
24
+ },
25
+ "devDependencies": {
26
+ "@babel/core": "^7.22.9",
27
+ "@babel/preset-env": "^7.22.9",
28
+ "@babel/preset-react": "^7.22.5",
29
+ "@babel/preset-typescript": "^7.23.3",
30
+ "@emotion/babel-plugin": "^11.11.0",
31
+ "@emotion/css": "^11.7.1",
32
+ "@emotion/jest": "^11.10.0",
33
+ "@emotion/react": "^11.8.2",
34
+ "@emotion/styled": "^11.8.1",
35
+ "@types/react": "^18.0.9",
36
+ "@types/react-dom": "^18.0.4",
37
+ "babel-loader": "^8.3.0",
38
+ "eslint-config-custom": "*",
39
+ "eslint-plugin-storybook": "^9.1.0",
40
+ "jest-config": "*",
41
+ "react": "^18.1.0",
42
+ "react-dom": "^18.2.0",
43
+ "tsconfig": "*",
44
+ "tsup": "^6.6.3",
45
+ "typescript": "^4.5.3"
46
+ },
47
+ "peerDependencies": {
48
+ "@emotion/css": "^11.7.1",
49
+ "@emotion/react": "^11.8.2",
50
+ "@emotion/styled": "^11.8.1",
51
+ "react": ">=17.0.2",
52
+ "react-dom": ">=17.0.2"
53
+ }
54
+ }