@fibery/ui-kit 1.7.2 → 1.7.4

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/LICENSE ADDED
@@ -0,0 +1,214 @@
1
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
2
+ LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
3
+ CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4
+
5
+ 1. DEFINITIONS
6
+
7
+ "Contribution" means:
8
+
9
+ a) in the case of the initial Contributor, the initial code and
10
+ documentation distributed under this Agreement, and
11
+
12
+ b) in the case of each subsequent Contributor:
13
+
14
+ i) changes to the Program, and
15
+
16
+ ii) additions to the Program;
17
+
18
+ where such changes and/or additions to the Program originate from and are
19
+ distributed by that particular Contributor. A Contribution 'originates' from
20
+ a Contributor if it was added to the Program by such Contributor itself or
21
+ anyone acting on such Contributor's behalf. Contributions do not include
22
+ additions to the Program which: (i) are separate modules of software
23
+ distributed in conjunction with the Program under their own license
24
+ agreement, and (ii) are not derivative works of the Program.
25
+
26
+ "Contributor" means any person or entity that distributes the Program.
27
+
28
+ "Licensed Patents" mean patent claims licensable by a Contributor which are
29
+ necessarily infringed by the use or sale of its Contribution alone or when
30
+ combined with the Program.
31
+
32
+ "Program" means the Contributions distributed in accordance with this
33
+ Agreement.
34
+
35
+ "Recipient" means anyone who receives the Program under this Agreement,
36
+ including all Contributors.
37
+
38
+ 2. GRANT OF RIGHTS
39
+
40
+ a) Subject to the terms of this Agreement, each Contributor hereby grants
41
+ Recipient a non-exclusive, worldwide, royalty-free copyright license to
42
+ reproduce, prepare derivative works of, publicly display, publicly perform,
43
+ distribute and sublicense the Contribution of such Contributor, if any, and
44
+ such derivative works, in source code and object code form.
45
+
46
+ b) Subject to the terms of this Agreement, each Contributor hereby grants
47
+ Recipient a non-exclusive, worldwide, royalty-free patent license under
48
+ Licensed Patents to make, use, sell, offer to sell, import and otherwise
49
+ transfer the Contribution of such Contributor, if any, in source code and
50
+ object code form. This patent license shall apply to the combination of the
51
+ Contribution and the Program if, at the time the Contribution is added by the
52
+ Contributor, such addition of the Contribution causes such combination to be
53
+ covered by the Licensed Patents. The patent license shall not apply to any
54
+ other combinations which include the Contribution. No hardware per se is
55
+ licensed hereunder.
56
+
57
+ c) Recipient understands that although each Contributor grants the licenses
58
+ to its Contributions set forth herein, no assurances are provided by any
59
+ Contributor that the Program does not infringe the patent or other
60
+ intellectual property rights of any other entity. Each Contributor disclaims
61
+ any liability to Recipient for claims brought by any other entity based on
62
+ infringement of intellectual property rights or otherwise. As a condition to
63
+ exercising the rights and licenses granted hereunder, each Recipient hereby
64
+ assumes sole responsibility to secure any other intellectual property rights
65
+ needed, if any. For example, if a third party patent license is required to
66
+ allow Recipient to distribute the Program, it is Recipient's responsibility
67
+ to acquire that license before distributing the Program.
68
+
69
+ d) Each Contributor represents that to its knowledge it has sufficient
70
+ copyright rights in its Contribution, if any, to grant the copyright license
71
+ set forth in this Agreement.
72
+
73
+ 3. REQUIREMENTS
74
+
75
+ A Contributor may choose to distribute the Program in object code form under
76
+ its own license agreement, provided that:
77
+
78
+ a) it complies with the terms and conditions of this Agreement; and
79
+
80
+ b) its license agreement:
81
+
82
+ i) effectively disclaims on behalf of all Contributors all warranties and
83
+ conditions, express and implied, including warranties or conditions of title
84
+ and non-infringement, and implied warranties or conditions of merchantability
85
+ and fitness for a particular purpose;
86
+
87
+ ii) effectively excludes on behalf of all Contributors all liability for
88
+ damages, including direct, indirect, special, incidental and consequential
89
+ damages, such as lost profits;
90
+
91
+ iii) states that any provisions which differ from this Agreement are offered
92
+ by that Contributor alone and not by any other party; and
93
+
94
+ iv) states that source code for the Program is available from such
95
+ Contributor, and informs licensees how to obtain it in a reasonable manner on
96
+ or through a medium customarily used for software exchange.
97
+
98
+ When the Program is made available in source code form:
99
+
100
+ a) it must be made available under this Agreement; and
101
+
102
+ b) a copy of this Agreement must be included with each copy of the Program.
103
+
104
+ Contributors may not remove or alter any copyright notices contained within
105
+ the Program.
106
+
107
+ Each Contributor must identify itself as the originator of its Contribution,
108
+ if any, in a manner that reasonably allows subsequent Recipients to identify
109
+ the originator of the Contribution.
110
+
111
+ 4. COMMERCIAL DISTRIBUTION
112
+
113
+ Commercial distributors of software may accept certain responsibilities with
114
+ respect to end users, business partners and the like. While this license is
115
+ intended to facilitate the commercial use of the Program, the Contributor who
116
+ includes the Program in a commercial product offering should do so in a
117
+ manner which does not create potential liability for other Contributors.
118
+ Therefore, if a Contributor includes the Program in a commercial product
119
+ offering, such Contributor ("Commercial Contributor") hereby agrees to defend
120
+ and indemnify every other Contributor ("Indemnified Contributor") against any
121
+ losses, damages and costs (collectively "Losses") arising from claims,
122
+ lawsuits and other legal actions brought by a third party against the
123
+ Indemnified Contributor to the extent caused by the acts or omissions of such
124
+ Commercial Contributor in connection with its distribution of the Program in
125
+ a commercial product offering. The obligations in this section do not apply
126
+ to any claims or Losses relating to any actual or alleged intellectual
127
+ property infringement. In order to qualify, an Indemnified Contributor must:
128
+ a) promptly notify the Commercial Contributor in writing of such claim, and
129
+ b) allow the Commercial Contributor to control, and cooperate with the
130
+ Commercial Contributor in, the defense and any related settlement
131
+ negotiations. The Indemnified Contributor may participate in any such claim
132
+ at its own expense.
133
+
134
+ For example, a Contributor might include the Program in a commercial product
135
+ offering, Product X. That Contributor is then a Commercial Contributor. If
136
+ that Commercial Contributor then makes performance claims, or offers
137
+ warranties related to Product X, those performance claims and warranties are
138
+ such Commercial Contributor's responsibility alone. Under this section, the
139
+ Commercial Contributor would have to defend claims against the other
140
+ Contributors related to those performance claims and warranties, and if a
141
+ court requires any other Contributor to pay any damages as a result, the
142
+ Commercial Contributor must pay those damages.
143
+
144
+ 5. NO WARRANTY
145
+
146
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
147
+ AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
148
+ EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
149
+ CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
150
+ PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
151
+ appropriateness of using and distributing the Program and assumes all risks
152
+ associated with its exercise of rights under this Agreement , including but
153
+ not limited to the risks and costs of program errors, compliance with
154
+ applicable laws, damage to or loss of data, programs or equipment, and
155
+ unavailability or interruption of operations.
156
+
157
+ 6. DISCLAIMER OF LIABILITY
158
+
159
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
160
+ CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
161
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
162
+ LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164
+ ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
165
+ EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
166
+ OF SUCH DAMAGES.
167
+
168
+ 7. GENERAL
169
+
170
+ If any provision of this Agreement is invalid or unenforceable under
171
+ applicable law, it shall not affect the validity or enforceability of the
172
+ remainder of the terms of this Agreement, and without further action by the
173
+ parties hereto, such provision shall be reformed to the minimum extent
174
+ necessary to make such provision valid and enforceable.
175
+
176
+ If Recipient institutes patent litigation against any entity (including a
177
+ cross-claim or counterclaim in a lawsuit) alleging that the Program itself
178
+ (excluding combinations of the Program with other software or hardware)
179
+ infringes such Recipient's patent(s), then such Recipient's rights granted
180
+ under Section 2(b) shall terminate as of the date such litigation is filed.
181
+
182
+ All Recipient's rights under this Agreement shall terminate if it fails to
183
+ comply with any of the material terms or conditions of this Agreement and
184
+ does not cure such failure in a reasonable period of time after becoming
185
+ aware of such noncompliance. If all Recipient's rights under this Agreement
186
+ terminate, Recipient agrees to cease use and distribution of the Program as
187
+ soon as reasonably practicable. However, Recipient's obligations under this
188
+ Agreement and any licenses granted by Recipient relating to the Program shall
189
+ continue and survive.
190
+
191
+ Everyone is permitted to copy and distribute copies of this Agreement, but in
192
+ order to avoid inconsistency the Agreement is copyrighted and may only be
193
+ modified in the following manner. The Agreement Steward reserves the right to
194
+ publish new versions (including revisions) of this Agreement from time to
195
+ time. No one other than the Agreement Steward has the right to modify this
196
+ Agreement. The Eclipse Foundation is the initial Agreement Steward. The
197
+ Eclipse Foundation may assign the responsibility to serve as the Agreement
198
+ Steward to a suitable separate entity. Each new version of the Agreement will
199
+ be given a distinguishing version number. The Program (including
200
+ Contributions) may always be distributed subject to the version of the
201
+ Agreement under which it was received. In addition, after a new version of
202
+ the Agreement is published, Contributor may elect to distribute the Program
203
+ (including its Contributions) under the new version. Except as expressly
204
+ stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
205
+ licenses to the intellectual property of any Contributor under this
206
+ Agreement, whether expressly, by implication, estoppel or otherwise. All
207
+ rights in the Program not expressly granted under this Agreement are
208
+ reserved.
209
+
210
+ This Agreement is governed by the laws of the State of New York and the
211
+ intellectual property laws of the United States of America. No party to this
212
+ Agreement will bring a legal action under this Agreement more than one year
213
+ after the cause of action arose. Each party waives its rights to a jury trial
214
+ in any resulting litigation.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@fibery/ui-kit",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "main": "index.ts",
5
5
  "private": false,
6
6
  "files": [
7
7
  "src/antd/styles.ts",
8
- "src/Button.ts",
8
+ "src/Button.tsx",
9
9
  "src/designSystem.ts",
10
10
  "src/theme-styles.ts",
11
11
  "src/theme-settings.ts",
@@ -21,19 +21,11 @@
21
21
  "src/error-alert.tsx",
22
22
  "src/Pallete.ts",
23
23
  "src/tooltip.tsx",
24
- "src/BackButton.tsx"
24
+ "src/BackButton.tsx",
25
+ "src/Button"
25
26
  ],
26
27
  "license": "UNLICENSED",
27
- "scripts": {
28
- "test": "TZ=Europe/Minsk jest",
29
- "test:ci": "yarn test --reporters=default --reporters=jest-junit",
30
- "test:coverage": "yarn test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/ui-kit --reporters=default --reporters=jest-junit",
31
- "lint": "eslint .",
32
- "generate-icons": "node scripts/generate-icons.mjs"
33
- },
34
28
  "dependencies": {
35
- "@fibery/helpers": "workspace:*",
36
- "@fibery/react": "workspace:*",
37
29
  "@linaria/core": "3.0.0-beta.15",
38
30
  "@linaria/react": "3.0.0-beta.15",
39
31
  "@popperjs/core": "2.11.6",
@@ -65,7 +57,9 @@
65
57
  "react-select-country-list": "2.2.1",
66
58
  "react-windowed-select": "5.0.0",
67
59
  "screenfull": "6.0.1",
68
- "ua-parser-js": "0.7.24"
60
+ "ua-parser-js": "0.7.24",
61
+ "@fibery/react": "1.0.0",
62
+ "@fibery/helpers": "1.0.2"
69
63
  },
70
64
  "peerDependencies": {
71
65
  "react": "^18.2.0",
@@ -74,8 +68,6 @@
74
68
  "devDependencies": {
75
69
  "@babel/core": "7.20.5",
76
70
  "@babel/runtime": "7.20.6",
77
- "@fibery/babel-preset": "workspace:*",
78
- "@fibery/eslint-config": "workspace:*",
79
71
  "@linaria/babel-preset": "3.0.0-beta.15",
80
72
  "@testing-library/dom": "8.19.1",
81
73
  "@testing-library/jest-dom": "5.16.5",
@@ -99,7 +91,9 @@
99
91
  "svg-parser": "2.0.4",
100
92
  "svgo": "2.8.0",
101
93
  "typescript": "5.0.3",
102
- "unist-util-reduce": "0.2.2"
94
+ "unist-util-reduce": "0.2.2",
95
+ "@fibery/babel-preset": "7.2.0",
96
+ "@fibery/eslint-config": "8.3.0"
103
97
  },
104
98
  "jest": {
105
99
  "testEnvironment": "jsdom",
@@ -124,5 +118,12 @@
124
118
  "setupFilesAfterEnv": [
125
119
  "<rootDir>/config/jest/testFrameworkSetup.js"
126
120
  ]
121
+ },
122
+ "scripts": {
123
+ "test": "TZ=Europe/Minsk jest",
124
+ "test:ci": "yarn test --reporters=default --reporters=jest-junit",
125
+ "test:coverage": "yarn test --coverage --coverageDirectory=${JEST_COVERAGE_RESULT_DIR:-$(pwd)}/coverage/ui-kit --reporters=default --reporters=jest-junit",
126
+ "lint": "eslint .",
127
+ "generate-icons": "node scripts/generate-icons.mjs"
127
128
  }
128
- }
129
+ }
@@ -0,0 +1,13 @@
1
+ import {forwardRef} from "react";
2
+ import AddIcon from "../icons/react/Add";
3
+ import {Button, ButtonProps} from "./button";
4
+
5
+ type Props = {
6
+ disableReason?: string;
7
+ } & ButtonProps;
8
+
9
+ export const AddButton = forwardRef<HTMLButtonElement, Props>(
10
+ ({disableReason = "", Icon = AddIcon, ...rest}, forwardedRef) => {
11
+ return <Button ref={forwardedRef} borderless Icon={Icon} title={disableReason} {...rest} />;
12
+ }
13
+ );
@@ -0,0 +1,26 @@
1
+ import {ButtonSize, Button} from "./button";
2
+ import BackIcon from "../icons/react/Back";
3
+
4
+ type Props = {
5
+ disabled?: boolean;
6
+ pending?: boolean;
7
+ onClick: () => unknown;
8
+ size?: ButtonSize;
9
+ color?: string;
10
+ };
11
+
12
+ export function BackButton({disabled, onClick, pending, size, color}: Props) {
13
+ return (
14
+ <Button
15
+ borderless
16
+ Icon={BackIcon}
17
+ disabled={disabled}
18
+ onClick={onClick}
19
+ pending={pending}
20
+ size={size}
21
+ color={color}
22
+ >
23
+ Back
24
+ </Button>
25
+ );
26
+ }
@@ -0,0 +1,190 @@
1
+ import {styled} from "@linaria/react";
2
+ import {ComponentPropsWithoutRef, forwardRef} from "react";
3
+ import {border, colors, fontWeight, getDarkenColor, getOpacities, opacity, ThemeColors} from "../designSystem";
4
+ import {useTheme} from "../ThemeProvider";
5
+
6
+ export const getMainColor = ({color, dangerous, theme}: {color?: string; dangerous?: boolean; theme: ThemeColors}) => {
7
+ if (color) {
8
+ return color;
9
+ }
10
+ if (dangerous) {
11
+ return theme.danger;
12
+ }
13
+ if (!theme) {
14
+ return colors.primary;
15
+ }
16
+ return theme.buttonColor;
17
+ };
18
+
19
+ const getBorderColor = ({
20
+ mainColor,
21
+ borderless,
22
+ primary,
23
+ }: {
24
+ mainColor: string;
25
+ borderless?: boolean;
26
+ primary?: boolean;
27
+ }) => {
28
+ if (borderless) {
29
+ return colors.transparent;
30
+ }
31
+ if (primary) {
32
+ return mainColor;
33
+ }
34
+ return getOpacities(mainColor).opacity15;
35
+ };
36
+
37
+ const getHoverBorderColor = ({
38
+ mainColor,
39
+ borderless,
40
+ primary,
41
+ hoverBgColor,
42
+ }: {
43
+ mainColor: string;
44
+ borderless?: boolean;
45
+ primary?: boolean;
46
+ hoverBgColor: string;
47
+ }) => {
48
+ if (borderless) {
49
+ return colors.transparent;
50
+ }
51
+ if (primary) {
52
+ return hoverBgColor;
53
+ }
54
+ return mainColor;
55
+ };
56
+
57
+ export const getTextColor = ({
58
+ mainColor,
59
+ primary,
60
+ theme,
61
+ }: {
62
+ mainColor: string;
63
+ primary?: boolean;
64
+ theme: ThemeColors;
65
+ }) => {
66
+ if (primary) {
67
+ return theme.buttonPrimaryTextColor;
68
+ }
69
+ return mainColor;
70
+ };
71
+
72
+ const getBgColor = ({mainColor, primary}: {mainColor: string; primary?: boolean}) => {
73
+ if (primary) {
74
+ return mainColor;
75
+ }
76
+ return colors.transparent;
77
+ };
78
+
79
+ const getHoverBgColor = ({
80
+ mainColor,
81
+ borderless,
82
+ primary,
83
+ }: {
84
+ mainColor: string;
85
+ primary?: boolean;
86
+ borderless?: boolean;
87
+ }) => {
88
+ if (primary) {
89
+ return getDarkenColor(mainColor);
90
+ }
91
+ if (borderless) {
92
+ return getOpacities(mainColor).opacity15;
93
+ }
94
+ return colors.transparent;
95
+ };
96
+
97
+ export const buttonBorderWidth = 1;
98
+
99
+ type StyledProps = {
100
+ textColor: string;
101
+ bgColor: string;
102
+ borderColor: string;
103
+ hoverBgColor: string;
104
+ hoverBorderColor: string;
105
+ borderWidth: number;
106
+ };
107
+
108
+ const StyledButtonBase = styled.button<StyledProps>`
109
+ display: block;
110
+ box-sizing: border-box;
111
+ font-weight: ${fontWeight.bold};
112
+ margin: 0;
113
+ border-radius: ${border.radius6}px;
114
+ border: 0;
115
+ border-width: ${({borderWidth}) => `${borderWidth}px`};
116
+ border-style: solid;
117
+ padding: 0;
118
+ cursor: pointer;
119
+ transition: all 150ms ease-out;
120
+ color: ${({textColor}) => textColor};
121
+ background-color: ${({bgColor}) => bgColor};
122
+ border-color: ${({borderColor}) => borderColor};
123
+
124
+ &:disabled {
125
+ cursor: default;
126
+ opacity: ${opacity.opacity40};
127
+ }
128
+
129
+ &:focus {
130
+ outline: none;
131
+ }
132
+
133
+ &:focus-visible {
134
+ box-shadow: ${({borderColor}) => `0 0 0 3px ${getOpacities(borderColor).opacity25}`};
135
+ background-color: ${({hoverBgColor}) => hoverBgColor};
136
+ border-color: ${({hoverBorderColor}) => hoverBorderColor};
137
+ }
138
+
139
+ &:hover:not(:disabled) {
140
+ background-color: ${({hoverBgColor}) => hoverBgColor};
141
+ border-color: ${({hoverBorderColor}) => hoverBorderColor};
142
+ }
143
+ `;
144
+
145
+ export type ButtonBaseProps = {
146
+ dataId?: string;
147
+ color?: string;
148
+ primary?: boolean;
149
+ dangerous?: boolean;
150
+ borderless?: boolean;
151
+ } & ComponentPropsWithoutRef<"button">;
152
+ export const ButtonBase = forwardRef<HTMLButtonElement, ButtonBaseProps>(function ButtonBase(
153
+ {primary, color, borderless, dangerous, className, type = "button", dataId, ...buttonProps},
154
+ ref
155
+ ) {
156
+ const theme = useTheme();
157
+
158
+ const mainColor = getMainColor({color, dangerous, theme});
159
+ const textColor = getTextColor({mainColor, primary, theme});
160
+ const bgColor = getBgColor({mainColor, primary});
161
+ const hoverBgColor = getHoverBgColor({mainColor, borderless, primary});
162
+ const borderColor = getBorderColor({mainColor, borderless, primary});
163
+ const hoverBorderColor = getHoverBorderColor({
164
+ mainColor,
165
+ borderless,
166
+ primary,
167
+ hoverBgColor,
168
+ });
169
+ const borderWidth = borderless ? 0 : buttonBorderWidth;
170
+
171
+ const styledProps: StyledProps = {
172
+ bgColor,
173
+ borderColor,
174
+ hoverBgColor,
175
+ hoverBorderColor,
176
+ textColor,
177
+ borderWidth,
178
+ };
179
+
180
+ return (
181
+ <StyledButtonBase
182
+ ref={ref}
183
+ type={type}
184
+ className={className}
185
+ data-testid={dataId}
186
+ {...styledProps}
187
+ {...buttonProps}
188
+ />
189
+ );
190
+ });
@@ -0,0 +1,76 @@
1
+ import {Children, cloneElement, CSSProperties, ReactElement} from "react";
2
+ import {css, cx} from "@linaria/core";
3
+ import {border} from "../designSystem";
4
+
5
+ const ordersInRowGroup = {
6
+ first: css`
7
+ ${{
8
+ display: "inline-flex",
9
+ borderRadius: `${border.radius6}px 0 0 ${border.radius6}px`,
10
+ marginRight: -1,
11
+ }}
12
+ `,
13
+ middle: css`
14
+ ${{
15
+ display: "inline-flex",
16
+ borderRadius: border.radius0,
17
+ marginRight: -1,
18
+ }}
19
+ `,
20
+ last: css`
21
+ ${{
22
+ display: "inline-flex",
23
+ borderRadius: `0 ${border.radius6}px ${border.radius6}px 0`,
24
+ }}
25
+ `,
26
+ };
27
+
28
+ const ordersInColumnGroup = {
29
+ first: css`
30
+ ${{
31
+ display: "inline-flex",
32
+ borderRadius: `${border.radius6}px ${border.radius6}px 0 0 `,
33
+ marginBottom: -1,
34
+ }}
35
+ `,
36
+ middle: css`
37
+ ${{
38
+ display: "inline-flex",
39
+ borderRadius: border.radius0,
40
+ marginBottom: -1,
41
+ }}
42
+ `,
43
+ last: css`
44
+ ${{
45
+ display: "inline-flex",
46
+ borderRadius: `0 0 ${border.radius6}px ${border.radius6}px`,
47
+ }}
48
+ `,
49
+ };
50
+
51
+ export interface ButtonGroupProps {
52
+ direction: CSSProperties["flexDirection"];
53
+ children: ReactElement[];
54
+ }
55
+
56
+ export function ButtonGroup({direction, children}: ButtonGroupProps) {
57
+ return (
58
+ <div
59
+ style={{
60
+ display: "flex",
61
+ alignItems: "flex-start",
62
+ flexDirection: direction,
63
+ }}
64
+ >
65
+ {Children.map(children, (child, index) => {
66
+ const inGroup = index === 0 ? "first" : index === children.length - 1 ? "last" : "middle";
67
+ return cloneElement(child, {
68
+ className: cx(
69
+ child.props.className,
70
+ direction === "row" ? ordersInRowGroup[inGroup] : ordersInColumnGroup[inGroup]
71
+ ),
72
+ });
73
+ })}
74
+ </div>
75
+ );
76
+ }
@@ -0,0 +1,242 @@
1
+ import {hasNonEmptyChild} from "@fibery/react/src/has-non-empty-child";
2
+ import {css} from "@linaria/core";
3
+ import {styled} from "@linaria/react";
4
+ import cx from "classnames";
5
+ import _ from "lodash";
6
+ import React, {forwardRef} from "react";
7
+ import {ButtonBase, ButtonBaseProps, buttonBorderWidth, getMainColor, getTextColor} from "./button-base";
8
+ import {border, colors, getOpacities, opacity, space, textStyles} from "../designSystem";
9
+ import MoreIcon from "../icons/react/More";
10
+ import MoreCompactIcon from "../icons/react/MoreCompact";
11
+ import {IconBaseProps} from "../icons/types";
12
+ import {Item} from "../Item";
13
+ import {Spinner} from "../loaders";
14
+ import {useTheme} from "../ThemeProvider";
15
+
16
+ type PositionInGroup = "first" | "middle" | "last";
17
+
18
+ export const ButtonSize = {
19
+ superSmall: ":button-size/super-small",
20
+ small: ":button-size/small",
21
+ normal: ":button-size/normal",
22
+ big: ":button-size/big",
23
+ } as const;
24
+ export type ButtonSize = (typeof ButtonSize)[keyof typeof ButtonSize];
25
+
26
+ const FontSizes = {
27
+ ":button-size/super-small": 10,
28
+ ":button-size/small": 12,
29
+ ":button-size/normal": 14,
30
+ ":button-size/big": 16,
31
+ } as const;
32
+
33
+ const HorizontalPaddings = {
34
+ ":button-size/super-small": 4,
35
+ ":button-size/small": 8,
36
+ ":button-size/normal": 12,
37
+ ":button-size/big": 16,
38
+ } as const;
39
+
40
+ const IconSizes = {
41
+ ":button-size/super-small": 16,
42
+ ":button-size/small": 18,
43
+ ":button-size/normal": 20,
44
+ ":button-size/big": 22,
45
+ };
46
+
47
+ type StyledProps = {
48
+ buttonSize: ButtonSize;
49
+ borderless?: boolean;
50
+ buttonWidth?: number | string;
51
+ buttonHeight?: number | string;
52
+ };
53
+
54
+ const getFontSize = ({buttonSize}: StyledProps) => FontSizes[buttonSize];
55
+ const getButtonMinSize = ({buttonSize}: StyledProps) => FontSizes[buttonSize] * 2;
56
+ const getHorizontalPadding = ({buttonSize, borderless}: StyledProps) =>
57
+ borderless ? HorizontalPaddings[buttonSize] : HorizontalPaddings[buttonSize] - buttonBorderWidth;
58
+
59
+ const StyledButton = styled(ButtonBase)<StyledProps>`
60
+ display: flex;
61
+ justify-content: center;
62
+ align-items: center;
63
+ vertical-align: middle;
64
+ position: relative;
65
+
66
+ width: ${({buttonWidth = "auto"}) => (typeof buttonWidth === "string" ? buttonWidth : `${buttonWidth}px`)};
67
+ height: ${({buttonHeight = "auto"}) => (typeof buttonHeight === "string" ? buttonHeight : `${buttonHeight}px`)};
68
+
69
+ font-size: ${getFontSize}px;
70
+ min-height: ${getButtonMinSize}px;
71
+ min-width: ${getButtonMinSize}px;
72
+ padding-left: ${getHorizontalPadding}px;
73
+ padding-right: ${getHorizontalPadding}px;
74
+ `;
75
+ export const buttonClassName = StyledButton;
76
+
77
+ // TODO: should be a different component, e.g. ButtonGroup
78
+ const ordersInGroup = {
79
+ first: css`
80
+ ${{
81
+ display: "inline-flex",
82
+ borderRadius: `${border.radius6}px 0 0 ${border.radius6}px`,
83
+ marginRight: -1,
84
+ }}
85
+ `,
86
+ middle: css`
87
+ ${{
88
+ display: "inline-flex",
89
+ borderRadius: border.radius0,
90
+ marginRight: -1,
91
+ }}
92
+ `,
93
+ last: css`
94
+ ${{
95
+ display: "inline-flex",
96
+ borderRadius: `0 ${border.radius6}px ${border.radius6}px 0`,
97
+ }}
98
+ `,
99
+ };
100
+
101
+ const getSpinnerColor = ({mainColor, primary}: {mainColor: string; primary?: boolean}) => {
102
+ if (primary) {
103
+ return colors.inversedTextColor;
104
+ }
105
+ return mainColor;
106
+ };
107
+
108
+ const getIconMagicConstants = _.memoize((size: ButtonSize) => {
109
+ const iconSize = IconSizes[size];
110
+
111
+ const leftContainerSize = 8;
112
+ const leftContainerMarginRight = iconSize - leftContainerSize;
113
+
114
+ return {iconSize, leftContainerSize, leftContainerMarginRight};
115
+ });
116
+
117
+ const shortcutStyle = css`
118
+ ${{
119
+ ...textStyles.small,
120
+ color: "currentColor",
121
+ borderRadius: border.radius4,
122
+ paddingLeft: space.xs,
123
+ paddingRight: space.xs,
124
+ paddingBottom: space.xxs,
125
+ marginRight: -space.xs,
126
+ marginLeft: space.xxs,
127
+ opacity: opacity.opacity80,
128
+ display: "inline-block",
129
+ }}
130
+ `;
131
+
132
+ const leftContainerMarginRightVar = "--fibery-button-left-container-margin-right";
133
+
134
+ const leftContainerClassName = css`
135
+ margin-right: var(${leftContainerMarginRightVar});
136
+ `;
137
+
138
+ export type ButtonProps = ButtonBaseProps & {
139
+ size?: ButtonSize;
140
+ pending?: boolean;
141
+ Icon?: ((props: IconBaseProps) => JSX.Element) | null;
142
+ inGroup?: PositionInGroup;
143
+ shortcut?: string;
144
+ noOverflow?: boolean;
145
+ width?: string | number;
146
+ height?: string | number;
147
+ };
148
+
149
+ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
150
+ {
151
+ disabled,
152
+ pending,
153
+ Icon,
154
+ inGroup,
155
+ shortcut,
156
+ noOverflow = true,
157
+ width,
158
+ height,
159
+ size = ":button-size/normal",
160
+ className,
161
+ children,
162
+ ...baseProps
163
+ },
164
+ forwardedRef
165
+ ) {
166
+ const theme = useTheme();
167
+ const mainColor = getMainColor({color: baseProps.color, dangerous: baseProps.dangerous, theme});
168
+ const textColor = getTextColor({mainColor, primary: baseProps.primary, theme});
169
+ const spinnerBgColor = getOpacities(textColor).opacity25;
170
+ const spinnerColor = getSpinnerColor({mainColor, primary: baseProps.primary});
171
+
172
+ const {iconSize, leftContainerSize, leftContainerMarginRight} = getIconMagicConstants(size);
173
+
174
+ const leftContainer = pending ? (
175
+ <Spinner backgroundColor={spinnerBgColor} color={spinnerColor} size={iconSize} containerSize={leftContainerSize} />
176
+ ) : Icon ? (
177
+ <Icon color={textColor} iconSize={iconSize} containerSize={leftContainerSize} />
178
+ ) : null;
179
+
180
+ const styleVariable: StyledProps = {
181
+ buttonHeight: height,
182
+ buttonWidth: width,
183
+ buttonSize: size,
184
+ borderless: baseProps.borderless,
185
+ };
186
+
187
+ const isDisabled = disabled || pending;
188
+
189
+ return (
190
+ <StyledButton
191
+ {...styleVariable}
192
+ ref={forwardedRef}
193
+ onClick={!isDisabled && baseProps.onClick ? baseProps.onClick : _.noop}
194
+ disabled={isDisabled}
195
+ className={cx(className, inGroup && ordersInGroup[inGroup])}
196
+ {...baseProps}
197
+ >
198
+ <Item
199
+ leftContainer={leftContainer}
200
+ style={
201
+ {
202
+ [leftContainerMarginRightVar]: `${leftContainerMarginRight}px`,
203
+ } as React.CSSProperties
204
+ }
205
+ containerClassName={cx({[leftContainerClassName]: leftContainer && hasNonEmptyChild(children)})}
206
+ rightContainer={shortcut && <span className={cx(shortcutStyle)}>{shortcut}</span>}
207
+ noOverflow={noOverflow}
208
+ >
209
+ {children}
210
+ </Item>
211
+ </StyledButton>
212
+ );
213
+ });
214
+
215
+ // TODO can be inlined
216
+ export function ActionsButton({
217
+ onClick,
218
+ label = ``,
219
+ disabled,
220
+ }: {
221
+ onClick: ButtonProps["onClick"];
222
+ label?: string;
223
+ disabled?: boolean;
224
+ }) {
225
+ return <Button Icon={MoreIcon} onClick={onClick} borderless aria-label={label} disabled={disabled} />;
226
+ }
227
+
228
+ export const ActionsButtonCompact = forwardRef<HTMLButtonElement, ButtonProps & {inverted?: boolean}>(
229
+ ({inverted, ...rest}, ref) => {
230
+ const theme = useTheme();
231
+ return (
232
+ <Button
233
+ ref={ref}
234
+ size={":button-size/small"}
235
+ Icon={MoreCompactIcon}
236
+ color={inverted ? colors.inversedTextColor : theme.buttonColor}
237
+ borderless
238
+ {...rest}
239
+ />
240
+ );
241
+ }
242
+ );
@@ -0,0 +1,15 @@
1
+ import {forwardRef} from "react";
2
+ import {Tooltip, TooltipProps} from "../tooltip";
3
+ import {IconButton, IconButtonProps} from "./icon-button";
4
+
5
+ type IconButtonTooltipProps = Pick<TooltipProps, "title" | "description" | "content" | "side">;
6
+
7
+ export const IconButtonWithTooltip = forwardRef<HTMLButtonElement, IconButtonTooltipProps & IconButtonProps>(
8
+ function IconButtonWithTooltip({title, description, content, side, ...props}, ref) {
9
+ return (
10
+ <Tooltip title={title} description={description} content={content} side={side}>
11
+ <IconButton ref={ref} {...props} />
12
+ </Tooltip>
13
+ );
14
+ }
15
+ );
@@ -0,0 +1,42 @@
1
+ import {styled} from "@linaria/react";
2
+ import {Children, cloneElement, forwardRef} from "react";
3
+ import {ButtonBase, ButtonBaseProps} from "./button-base";
4
+ import {IconProps} from "../icons/types";
5
+
6
+ export type IconButtonSize = "super-small" | "small" | "normal" | "big";
7
+
8
+ export type IconButtonProps = Omit<ButtonBaseProps, "borderless"> & {
9
+ size?: IconButtonSize;
10
+ };
11
+
12
+ const Paddings = {
13
+ "super-small": 0,
14
+ small: 2,
15
+ normal: 4,
16
+ big: 6,
17
+ };
18
+
19
+ type StyledProps = {
20
+ /** The size of the component. `super-small` is equivalent to the dense button styling */
21
+ size: IconButtonSize;
22
+ };
23
+
24
+ const getPadding = ({size}: StyledProps) => Paddings[size];
25
+
26
+ const StyledIconButton = styled(ButtonBase)<StyledProps>`
27
+ padding: ${getPadding}px;
28
+ `;
29
+
30
+ export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(
31
+ {size = "normal", children, className, ...rest},
32
+ ref
33
+ ) {
34
+ const iconNode = Children.only(children) as React.ReactElement<IconProps>;
35
+
36
+ return (
37
+ <StyledIconButton ref={ref} size={size} className={className} borderless {...rest}>
38
+ {/* maybe better to use css variables? */}
39
+ {cloneElement(iconNode, {color: iconNode.props.color || "inherit"})}
40
+ </StyledIconButton>
41
+ );
42
+ });
File without changes