diginet-core-ui 1.3.93-beta.2 → 1.3.93-beta.3

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.
@@ -1,37 +1,17 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useRef, useMemo, forwardRef, useImperativeHandle } from 'react';
4
- import PropTypes from 'prop-types';
5
- import { jsx, css } from '@emotion/core';
3
+ import { css, jsx } from '@emotion/core';
4
+ import { CircularProgress, Icon } from "./..";
6
5
  import OptionWrapper from "../others/option-wrapper";
7
- import * as allColors from "../../styles/colors";
6
+ import PropTypes from 'prop-types';
7
+ import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
8
8
  import { hexToRGBA } from "../../styles/color-helper";
9
+ import * as allColors from "../../styles/colors";
10
+ import { alphaPseudo, bgColor, border, borderColor, borderNone, borderRadius, boxBorder, cursorNotAllowed, cursorPointer, displayFlex, displayInlineFlex, flexRow, itemsCenter, justifyCenter, outlineNone, parseMinWidthHeight, parseWidthHeight, pd, pointerEventsNone, positionRelative, textColor, userSelectNone } from "../../styles/general";
11
+ import { getColor } from "../../styles/utils";
9
12
  import { capitalize, classNames, refType as ref } from "../../utils";
10
- import Icon from "../../icons";
13
+ import { getRippleColor } from '.';
11
14
  import Ripple from "./ripple-effect";
12
- import { getClassNameFromColor, getRippleColor } from '.';
13
- import CircularProgress from "../progress/circular";
14
- import { itemsCenter, bgTransparent, border, boxBorder, borderNone, borderRadius4px, borderRadius50, cursorPointer, flexRow, displayInlineFlex, justifyCenter, outlineNone, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionRelative, userSelectNone } from "../../styles/general";
15
- import { useColor as colors, useTheme } from "../../theme";
16
- const {
17
- colors: {
18
- system: {
19
- active,
20
- disabled: systemDisabled,
21
- rest: systemRest,
22
- white: systemWhite
23
- },
24
- semantic: {
25
- success: semanticSuccess,
26
- warning: semanticWarning,
27
- danger: semanticDanger,
28
- info: semanticInfo
29
- },
30
- fill: {
31
- disabled: fillDisabled
32
- }
33
- }
34
- } = useTheme();
35
15
  const sizeMap = new Map([['tiny', {
36
16
  buttonSize: '24px',
37
17
  iconSize: '16px'
@@ -51,12 +31,7 @@ const sizeMap = new Map([['tiny', {
51
31
  buttonSize: '96px',
52
32
  iconSize: '56px'
53
33
  }]]);
54
- const iconColorMap = new Map([['Close', semanticDanger], ['Cancel', semanticDanger], ['Approval', semanticSuccess], ['Delete', semanticWarning], ['Trash', semanticWarning], ['Edit', semanticInfo], ['EditV2', semanticInfo], ['View', semanticInfo]]);
55
- const alphaArr = {
56
- hover: 0.1,
57
- focus: 0.2,
58
- active: 0.3
59
- };
34
+ const iconColorMap = new Map([['Close', 'semantic.danger'], ['Cancel', 'semantic.danger'], ['Approval', 'semantic.success'], ['Delete', 'semantic.warning'], ['Trash', 'semantic.warning'], ['Edit', 'semantic.info'], ['EditV2', 'semantic.info'], ['View', 'semantic.info']]);
60
35
  const alphaLoading = 0.2;
61
36
  // customIconSize calculated based on design size
62
37
  // Button size <= 24 => icon size = Button size - 8
@@ -94,14 +69,20 @@ const ButtonIcon = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
94
69
  var _sizeMap$get, _sizeMap$get2;
95
70
  const ref = useRef(null);
96
71
  const rippleRef = useRef(null);
72
+ const isColorDefault = colorProp === 'default';
73
+ const isViewTypeGhost = viewType === 'ghost';
97
74
  const buttonSize = ((_sizeMap$get = sizeMap.get(size)) === null || _sizeMap$get === void 0 ? void 0 : _sizeMap$get.buttonSize) || '40px';
98
75
  const iconSize = width ? isNaN(width) ? '60%' : customIconSize(parseInt(width)) + 'px' : ((_sizeMap$get2 = sizeMap.get(size)) === null || _sizeMap$get2 === void 0 ? void 0 : _sizeMap$get2.iconSize) || '24px';
99
- const isViewTypeGhost = viewType === 'ghost';
100
- const color = colors[colorProp] || colorProp;
101
- colorHover = colors[colorHover] || colorHover;
102
- const _ButtonRootCSS = ButtonRootCSS(circular, colorHover, color, name);
76
+ const _ButtonRootCSS = ButtonRootCSS(circular, colorHover, colorProp, name, isColorDefault, viewType, loading);
103
77
  const _ButtonSizeCSS = ButtonSizeCSS(width, height, buttonSize, iconSize);
104
78
  const _ButtonIconCSS = ButtonIconCSS(iconSize);
79
+ const _onClick = event => {
80
+ event.persist();
81
+ onClick && event.stopPropagation();
82
+ if (disabled || loading) return;
83
+ if (!isViewTypeGhost) rippleRef.current.start(event);
84
+ onClick && onClick(event);
85
+ };
105
86
  useImperativeHandle(reference, () => {
106
87
  const currentRef = ref.current || {};
107
88
  currentRef.element = ref.current;
@@ -112,22 +93,15 @@ const ButtonIcon = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
112
93
  currentRef.instance = _instance;
113
94
  return currentRef;
114
95
  });
115
- const _onClick = event => {
116
- event.persist();
117
- onClick && event.stopPropagation();
118
- if (disabled || loading) return;
119
- if (!isViewTypeGhost) rippleRef.current.start(event);
120
- onClick && onClick(event);
121
- };
122
96
  return useMemo(() => {
123
97
  return jsx("button", {
124
- css: [_ButtonRootCSS, _ButtonSizeCSS, disabled && ButtonDisabledCSS],
98
+ css: [_ButtonRootCSS, _ButtonSizeCSS],
125
99
  ref: ref,
126
100
  id: id,
127
101
  disabled: disabled,
128
102
  style: style,
129
103
  onClick: _onClick,
130
- className: classNames('DGN-UI-ButtonIcon', viewType, getClassNameFromColor(colorProp), size, loading && 'button-icon--loading', className)
104
+ className: classNames('DGN-UI-ButtonIcon', viewType, size, className)
131
105
  }, loading && IconLoadingView(iconSize), !loading && jsx("span", {
132
106
  className: 'DGN-UI-ButtonIcon-Icon',
133
107
  css: _ButtonIconCSS
@@ -142,9 +116,10 @@ const ButtonIcon = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
142
116
  color: getRippleColor(colorProp, viewType, allColors),
143
117
  circular: circular
144
118
  }));
145
- }, [children, circular, className, colorProp, colorHover, disabled, height, id, loading, name, onClick, size, style, viewBox, viewType, width]);
119
+ }, [children, circular, className, colorHover, colorProp, disabled, height, id, loading, name, onClick, size, style, viewBox, viewType, width]);
146
120
  }));
147
121
  const ButtonIconCSS = iconSize => css`
122
+ ${displayFlex};
148
123
  ${flexRow};
149
124
  ${positionRelative};
150
125
  ${boxBorder};
@@ -153,21 +128,6 @@ const ButtonIconCSS = iconSize => css`
153
128
  ${parseWidthHeight(iconSize)};
154
129
  ${parseMinWidthHeight(iconSize)};
155
130
  `;
156
- const ButtonDisabledCSS = `
157
- cursor: not-allowed !important;
158
- color: ${systemDisabled} !important;
159
- &.outlined {
160
- border-color: ${systemDisabled} !important;
161
- background-color: transparent !important;
162
- }
163
- &.filled {
164
- background-color: ${fillDisabled} !important;
165
- filter: brightness(1) !important;
166
- }
167
- &.text {
168
- background-color: transparent !important;
169
- }
170
- `;
171
131
  const ButtonSizeCSS = (width, height, buttonSize, iconSize) => css`
172
132
  ${parseWidthHeight(width || buttonSize, height || buttonSize)};
173
133
  ${parseMinWidthHeight(width || buttonSize, height || buttonSize)};
@@ -176,7 +136,7 @@ const ButtonSizeCSS = (width, height, buttonSize, iconSize) => css`
176
136
  ${parseMinWidthHeight(width || iconSize, height || iconSize)};
177
137
  }
178
138
  `;
179
- const ButtonRootCSS = (circular, colorHover, color, name) => css`
139
+ const ButtonRootCSS = (circular, colorHover, color, name, isColorDefault, viewType, loading) => css`
180
140
  ${displayInlineFlex};
181
141
  ${positionRelative};
182
142
  ${justifyCenter};
@@ -185,46 +145,55 @@ const ButtonRootCSS = (circular, colorHover, color, name) => css`
185
145
  ${boxBorder};
186
146
  ${cursorPointer};
187
147
  ${userSelectNone};
188
- ${circular ? borderRadius50 : borderRadius4px};
189
- padding: 0;
148
+ ${borderRadius(circular ? '50%' : 4)};
149
+ ${pd(0)};
190
150
  transition: background-color 0.5s, filter 0.5s;
191
- &.button-icon--loading {
192
- ${pointerEventsNone};
193
- }
194
- &.outlined {
195
- ${bgTransparent};
196
- ${border(1, color)}
197
- color: ${color};
198
- &.button-icon--loading {
199
- background-color: ${hexToRGBA(color, alphaLoading)};
200
- }
201
- ${Object.keys(alphaArr).map(key => `&:${key} {
202
- background-color: ${hexToRGBA(color, alphaArr[key])};
203
- }`)}
204
- &.default {
205
- ${border(1, systemRest)};
206
- color: ${systemRest};
207
- &.button-icon--loading,
151
+ ${loading && pointerEventsNone};
152
+ ${viewType === 'outlined' && css`
153
+ ${bgColor('transparent')};
154
+ ${border(1, color)};
155
+ ${textColor(color)};
156
+ ${loading && css`
157
+ ${bgColor(hexToRGBA(color, alphaLoading))};
158
+ `}
159
+ ${Object.keys(alphaPseudo).map(key => css`
160
+ &: ${key} {
161
+ ${bgColor(hexToRGBA(color, alphaPseudo[key]))};
162
+ }
163
+ `)}
164
+ ${isColorDefault && css`
165
+ ${border(1, 'system/rest')};
166
+ ${textColor('system/rest')};
167
+ ${loading && css`
168
+ ${textColor(colorHover)};
169
+ ${borderColor(colorHover)};
170
+ ${bgColor(hexToRGBA(colorHover, alphaLoading))};
171
+ `}
208
172
  &:hover,
209
173
  &:focus,
210
174
  &:active {
211
- color: ${colorHover};
212
- border-color: ${colorHover};
213
- }
214
- &.button-icon--loading {
215
- background-color: ${hexToRGBA(colorHover, alphaLoading)};
175
+ ${textColor(colorHover)};
176
+ ${borderColor(colorHover)};
216
177
  }
217
- ${Object.keys(alphaArr).map(key => `&:${key} {
218
- background-color: ${hexToRGBA(colorHover, alphaArr[key])};
219
- }`)}// &:hover | &:focus | &:active
178
+ ${Object.keys(alphaPseudo).map(key => css`
179
+ &: ${key} {
180
+ ${bgColor(hexToRGBA(colorHover, alphaPseudo[key]))};
181
+ }
182
+ `)}// &:hover | &:focus | &:active
183
+ `}
184
+ :disabled {
185
+ ${borderColor('system/disabled')};
186
+ ${bgColor('transparent')};
220
187
  }
221
- }
222
- &.filled {
188
+ `}
189
+ ${viewType === 'filled' && css`
223
190
  ${borderNone};
224
- background-color: ${color};
225
- color: ${color === systemWhite ? systemRest : systemWhite};
191
+ ${textColor(color === getColor('system.white') ? 'system.rest' : 'system.white')};
192
+ ${bgColor(color)};
226
193
  font-weight: bold;
227
- &.button-icon--loading,
194
+ ${loading && css`
195
+ filter: brightness(0.85);
196
+ `}
228
197
  &:hover,
229
198
  &:focus {
230
199
  filter: brightness(0.85);
@@ -232,47 +201,54 @@ const ButtonRootCSS = (circular, colorHover, color, name) => css`
232
201
  &:active {
233
202
  filter: brightness(0.7);
234
203
  }
235
- &.default {
236
- background-color: ${systemRest};
237
- &.button-icon--loading,
204
+ ${isColorDefault && css`
205
+ ${bgColor('system/rest')};
206
+ ${loading && bgColor('system/active')};
238
207
  &:hover,
239
208
  &:focus,
240
209
  &:active {
241
- background-color: ${colorHover};
210
+ ${bgColor(colorHover)};
242
211
  }
212
+ `}
213
+ :disabled {
214
+ ${bgColor('fill/disabled')};
215
+ filter: brightness(1);
243
216
  }
244
- }
245
- &.text {
217
+ `}
218
+ ${viewType === 'text' && css`
246
219
  ${borderNone};
247
- ${bgTransparent};
248
- color: ${color};
249
- &.button-icon--loading {
250
- background-color: ${hexToRGBA(color, alphaLoading)};
220
+ ${textColor(color)};
221
+ ${bgColor('transparent')};
222
+ ${loading && bgColor(hexToRGBA(color, alphaLoading))};
223
+ ${Object.keys(alphaPseudo).map(key => css`
224
+ &: ${key} {
225
+ ${bgColor(hexToRGBA(color, alphaPseudo[key]))};
226
+ }
227
+ `)}
228
+ ${isColorDefault && css`
229
+ ${textColor('system/rest')};
230
+ ${loading && css`
231
+ ${textColor('system/active')};
232
+ ${bgColor(hexToRGBA(colorHover, alphaLoading))};
233
+ `}
234
+ ${Object.keys(alphaPseudo).map(key => css`
235
+ &: ${key} {
236
+ ${textColor(colorHover)};
237
+ ${bgColor(hexToRGBA(colorHover, alphaPseudo[key]))};
238
+ }
239
+ `)}
240
+ `}
241
+ :disabled {
242
+ ${bgColor('transparent')};
251
243
  }
252
- ${Object.keys(alphaArr).map(key => `&:${key} {
253
- background-color: ${hexToRGBA(color, alphaArr[key])};
254
- }`)}
255
- &.default {
256
- color: ${systemRest};
257
- &:hover,
258
- &:focus,
259
- &:active {
260
- color: ${colorHover};
261
- }
262
- &.button-icon--loading {
263
- color: ${active};
264
- background-color: ${hexToRGBA(colorHover, alphaLoading)};
265
- }
266
- ${Object.keys(alphaArr).map(key => `&:${key} {
267
- background-color: ${hexToRGBA(colorHover, alphaArr[key])};
268
- }`)}
269
- }
270
- }
271
- &.ghost {
272
- ${bgTransparent};
244
+ `}
245
+ ${viewType === 'ghost' && css`
273
246
  ${borderNone};
274
- color: ${color};
275
- &.loading,
247
+ ${bgColor('transparent')};
248
+ ${textColor(color)};
249
+ ${loading && css`
250
+ filter: brightness(0.85);
251
+ `}
276
252
  &:hover,
277
253
  &:focus {
278
254
  filter: brightness(0.85);
@@ -280,21 +256,25 @@ const ButtonRootCSS = (circular, colorHover, color, name) => css`
280
256
  &:active {
281
257
  filter: brightness(0.7);
282
258
  }
283
- &.default {
284
- color: ${systemRest};
259
+ ${isColorDefault && css`
260
+ ${textColor('system/rest')};
285
261
  &:hover,
286
262
  &:focus,
287
263
  &:active {
288
- color: ${iconColorMap.get(capitalize(name)) || colorHover};
264
+ ${textColor(iconColorMap.get(capitalize(name)) || colorHover)};
289
265
  }
290
- }
266
+ `}
267
+ `}
268
+ :disabled {
269
+ ${cursorNotAllowed};
270
+ ${textColor('system/disabled')};
291
271
  }
292
272
  `;
293
273
  ButtonIcon.defaultProps = {
294
274
  circular: false,
295
275
  className: '',
296
276
  color: 'default',
297
- colorHover: active,
277
+ colorHover: 'system/active',
298
278
  disabled: false,
299
279
  size: 'medium',
300
280
  viewBox: true,
@@ -47,9 +47,6 @@ export const getRippleColor = (color, viewType, colors) => {
47
47
  return rgbaToHexA(hslToRgb(fade(color, 0.5)));
48
48
  }
49
49
  };
50
- export const getClassNameFromColor = color => {
51
- return !isColor(color) && !isColorName(color) ? color : 'custom-color';
52
- };
53
50
  const iconSizeMap = new Map([['tiny', spacing([4])], ['small', spacing([5])], ['medium', spacing([6])], ['large', spacing([8])], ['giant', spacing([10])]]);
54
51
  const paddingSizeMap = new Map([['tiny', [1, 2]], ['small', [1.5, 3]], ['medium', [2, 4]], ['large', [2, 5]], ['giant', [2, 6]]]);
55
52
  const outlinedPaddingSizeMap = new Map([['tiny', [0.75, 1.75]], ['small', [1.25, 2.75]], ['medium', [1.75, 3.75]], ['large', [1.75, 4.75]], ['giant', [1.75, 5.75]]]);
@@ -408,19 +405,19 @@ Button.propTypes = {
408
405
  urlParams: PropTypes.object,
409
406
  /** The variant to use. */
410
407
  viewType: PropTypes.oneOf(['text', 'outlined', 'filled', 'link']),
411
- /**
412
- * ref methods (ref.current.instance.*method*)
413
- *
414
- * * option(): Gets all UI component properties
415
- * * Returns value - object
416
- * * option(optionName): Gets the value of a single property
417
- * * @param {optionName} - string
418
- * * Returns value - any
419
- * * option(optionName, optionValue): Updates the value of a single property
420
- * * @param {optionName} - string
421
- * * @param {optionValue} - any
422
- * * option(options): Updates the values of several properties
423
- * * @param {options} - object
408
+ /**
409
+ * ref methods (ref.current.instance.*method*)
410
+ *
411
+ * * option(): Gets all UI component properties
412
+ * * Returns value - object
413
+ * * option(optionName): Gets the value of a single property
414
+ * * @param {optionName} - string
415
+ * * Returns value - any
416
+ * * option(optionName, optionValue): Updates the value of a single property
417
+ * * @param {optionName} - string
418
+ * * @param {optionValue} - any
419
+ * * option(options): Updates the values of several properties
420
+ * * @param {options} - object
424
421
  */
425
422
  reference: ref
426
423
  };
@@ -1,25 +1,19 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
3
  import { css, jsx } from '@emotion/core';
4
+ import { ButtonIcon, Icon, Popover, Typography } from "./..";
4
5
  import PropTypes from 'prop-types';
5
6
  import React, { forwardRef, isValidElement, memo, useImperativeHandle, useMemo, useRef, useState } from 'react';
6
- import { ButtonIcon, Icon, Popover, Typography } from "../";
7
- import { itemsCenter, borderNone, cursorPointer, flexCol, flexRow, outlineNone, parseHeight } from "../../styles/general";
7
+ import { bgColor, borderNone, cursorPointer, displayFlex, flexCol, flexRow, gap, itemsCenter, outlineNone, parseHeight, pd, pdl } from "../../styles/general";
8
8
  import { useTheme } from "../../theme";
9
9
  import { classNames, refType as ref } from "../../utils";
10
10
  import OptionWrapper from "../others/option-wrapper";
11
11
  const {
12
12
  colors: {
13
13
  system: {
14
- dark: systemDark,
15
- white: systemWhite
16
- },
17
- fill: {
18
- hover: fillHover,
19
- pressed: fillPressed
14
+ dark: systemDark
20
15
  }
21
- },
22
- spacing
16
+ }
23
17
  } = useTheme();
24
18
  const ButtonMore = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
25
19
  action = {},
@@ -139,29 +133,30 @@ const ButtonMore = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
139
133
  }));
140
134
  const PopoverCSS = isOptionFull => css`
141
135
  ${isOptionFull ? flexCol : flexRow};
142
- padding: ${isOptionFull ? spacing([1, 0]) : spacing([0, 2])};
136
+ ${pd(isOptionFull ? [1, 0] : [0, 2])}
143
137
  `;
144
138
  const OptionFullCSS = css`
139
+ ${displayFlex};
145
140
  ${flexRow};
146
141
  ${itemsCenter};
147
142
  ${cursorPointer};
148
143
  ${outlineNone};
149
144
  ${borderNone}
150
145
  ${parseHeight(28)};
151
- padding: ${spacing([0, 4])};
152
- gap: ${spacing([0, 1])};
153
- background-color: ${systemWhite};
146
+ ${pd([0, 4])};
147
+ ${gap([0, 1])};
148
+ ${bgColor('system.white')};
154
149
  transition: all 0.5s ease;
155
150
  &:hover,
156
151
  &:focus {
157
- background-color: ${fillHover};
152
+ ${bgColor('fill.hover')};
158
153
  }
159
154
  &:active {
160
- background-color: ${fillPressed};
155
+ ${bgColor('fill.pressed')};
161
156
  }
162
157
  `;
163
158
  const ExtraPaddingCSS = css`
164
- padding-left: ${spacing([6])};
159
+ ${pdl([6])};
165
160
  `;
166
161
  ButtonMore.defaultProps = {
167
162
  buttonProps: {},
@@ -192,19 +187,19 @@ ButtonMore.propTypes = {
192
187
  popoverProp: PropTypes.object,
193
188
  /** Style inline of component. */
194
189
  style: PropTypes.object,
195
- /**
196
- * ref methods (ref.current.instance.*method*)
197
- *
198
- * * option(): Gets all UI component properties
199
- * * Returns value - object
200
- * * option(optionName): Gets the value of a single property
201
- * * @param {optionName} - string
202
- * * Returns value - any
203
- * * option(optionName, optionValue): Updates the value of a single property
204
- * * @param {optionName} - string
205
- * * @param {optionValue} - any
206
- * * option(options): Updates the values of several properties
207
- * * @param {options} - object
190
+ /**
191
+ * ref methods (ref.current.instance.*method*)
192
+ *
193
+ * * option(): Gets all UI component properties
194
+ * * Returns value - object
195
+ * * option(optionName): Gets the value of a single property
196
+ * * @param {optionName} - string
197
+ * * Returns value - any
198
+ * * option(optionName, optionValue): Updates the value of a single property
199
+ * * @param {optionName} - string
200
+ * * @param {optionValue} - any
201
+ * * option(options): Updates the values of several properties
202
+ * * @param {options} - object
208
203
  */
209
204
  reference: ref
210
205
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.93-beta.2",
3
+ "version": "1.3.93-beta.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",