@via-profit/ui-kit 0.1.0-rc.84 → 0.1.0-rc.85

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.
@@ -19,6 +19,7 @@ const AvatarIconWrapper_1 = __importDefault(require("./AvatarIconWrapper"));
19
19
  const AvatarTextWrapper_1 = __importDefault(require("./AvatarTextWrapper"));
20
20
  const AvatarContainer_1 = __importDefault(require("./AvatarContainer"));
21
21
  const AvatarPicture_1 = __importDefault(require("./AvatarPicture"));
22
+ const AvatarOnlineBadge_1 = __importDefault(require("./AvatarOnlineBadge"));
22
23
  const AvatarBase = (props, ref) => {
23
24
  const { children, src, color, alt, variant, overrides, isOnline } = props, nativeProps = __rest(props, ["children", "src", "color", "alt", "variant", "overrides", "isOnline"]);
24
25
  const overridesMap = react_1.default.useMemo(() => (Object.assign({ TextWrapper: AvatarTextWrapper_1.default,
@@ -27,7 +28,8 @@ const AvatarBase = (props, ref) => {
27
28
  Picture: AvatarPicture_1.default }, overrides)), [overrides]);
28
29
  return (react_1.default.createElement(overridesMap.Container, Object.assign({}, nativeProps, { color: color, ref: ref }),
29
30
  typeof src !== 'undefined' && src !== null && (src === null || src === void 0 ? void 0 : src.length) !== 0 && (react_1.default.createElement(overridesMap.IconWrapper, null,
30
- react_1.default.createElement(overridesMap.Picture, { src: src }))),
31
- (!src || src === null || (src === null || src === void 0 ? void 0 : src.length) === 0) && (react_1.default.createElement(overridesMap.TextWrapper, null, children))));
31
+ react_1.default.createElement(overridesMap.Picture, { src: src, variant: variant }))),
32
+ (!src || src === null || (src === null || src === void 0 ? void 0 : src.length) === 0) && (react_1.default.createElement(overridesMap.TextWrapper, null, children)),
33
+ isOnline && react_1.default.createElement(AvatarOnlineBadge_1.default, null)));
32
34
  };
33
35
  exports.default = react_1.default.forwardRef(AvatarBase);
@@ -28,7 +28,6 @@ const StyledAvatar = styled_1.default.span `
28
28
  width: ${({ size }) => size || '2.5em'};
29
29
  height: ${({ size }) => size || '2.5em'};
30
30
  display: inline-flex;
31
- overflow: hidden;
32
31
  align-items: center;
33
32
  color: ${({ color, theme }) => {
34
33
  switch (true) {
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  export type MimeType = 'image/webp' | 'image/jpeg' | 'image/png' | 'image/gif' | 'image/apng' | 'image/svg+xml' | 'image/bmp' | 'image/x-icon';
3
3
  export type SrcObject = {
4
- srcSet: string;
5
- type: MimeType;
6
- isDefault?: boolean;
4
+ readonly srcSet: string;
5
+ readonly type: MimeType;
6
+ readonly isDefault?: boolean;
7
7
  };
8
8
  export type AvatarPictureProps = React.HTMLAttributes<HTMLPictureElement> & {
9
9
  /**
@@ -20,6 +20,13 @@ export type AvatarPictureProps = React.HTMLAttributes<HTMLPictureElement> & {
20
20
  * ```
21
21
  */
22
22
  readonly src: SrcObject[];
23
+ /**
24
+ * Avatar style variant\
25
+ * Allowed variants: `circular`,`rounded` or `square`\
26
+ * \
27
+ * **Default**: `circular`
28
+ */
29
+ readonly variant?: 'circular' | 'rounded' | 'square';
23
30
  };
24
31
  declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLPictureElement> & {
25
32
  /**
@@ -36,5 +43,12 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
36
43
  * ```
37
44
  */
38
45
  readonly src: SrcObject[];
46
+ /**
47
+ * Avatar style variant\
48
+ * Allowed variants: `circular`,`rounded` or `square`\
49
+ * \
50
+ * **Default**: `circular`
51
+ */
52
+ readonly variant?: "square" | "circular" | "rounded" | undefined;
39
53
  } & React.RefAttributes<HTMLSpanElement>>;
40
54
  export default _default;
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  const react_1 = __importDefault(require("react"));
18
18
  const styled_1 = __importDefault(require("@emotion/styled"));
19
+ const react_2 = require("@emotion/react");
19
20
  const Picture = styled_1.default.picture `
20
21
  background-position: center;
21
22
  background-size: cover;
@@ -25,10 +26,29 @@ const Picture = styled_1.default.picture `
25
26
  width: 100%;
26
27
  height: 100%;
27
28
  }
29
+
30
+ ${({ $variant, theme }) => {
31
+ switch ($variant) {
32
+ case 'rounded':
33
+ return (0, react_2.css) `
34
+ border-radius: ${theme.shape.radiusFactor * 0.8}em;
35
+ overflow: hidden;
36
+ `;
37
+ case 'square':
38
+ return (0, react_2.css) `
39
+ border-radius: inherit;
40
+ `;
41
+ default:
42
+ return (0, react_2.css) `
43
+ border-radius: 100%;
44
+ overflow: hidden;
45
+ `;
46
+ }
47
+ }}
28
48
  `;
29
49
  const generateKey = () => (Math.random() * 10000).toFixed();
30
50
  const AvatarPicture = (props, ref) => {
31
- const { src } = props, nativeProps = __rest(props, ["src"]);
51
+ const { src, variant } = props, nativeProps = __rest(props, ["src", "variant"]);
32
52
  const defaultSrc = react_1.default.useMemo(() => {
33
53
  if (typeof src === 'undefined' || (src === null || src === void 0 ? void 0 : src.length) === 0) {
34
54
  return null;
@@ -44,7 +64,7 @@ const AvatarPicture = (props, ref) => {
44
64
  retData = src.find(src => src.type === 'image/jpeg');
45
65
  return retData ? retData : null;
46
66
  }, [src]);
47
- return (react_1.default.createElement(Picture, Object.assign({}, nativeProps, { ref: ref }),
67
+ return (react_1.default.createElement(Picture, Object.assign({}, nativeProps, { "$variant": variant, ref: ref }),
48
68
  src.map((_a) => {
49
69
  var { isDefault } = _a, srcProps = __rest(_a, ["isDefault"]);
50
70
  return (react_1.default.createElement("source", Object.assign({ key: generateKey() }, srcProps)));
package/Avatar/index.d.ts CHANGED
@@ -1,33 +1,5 @@
1
1
  import React from 'react';
2
- import { AvatarStandardProps } from './AvatarStandard';
3
- export type AvatarProps = AvatarStandardProps & {
4
- /**
5
- * Avatar style variant\
6
- * Allowed variants: `circular`, 'rounded' or `square`\
7
- * \
8
- * **Default**: `circular`
9
- */
10
- readonly variant?: 'circular' | 'rounded' | 'square';
11
- /**
12
- * Avatar size variant\
13
- * \
14
- * **Default**: `2.5em`
15
- */
16
- readonly size?: string;
17
- };
18
- declare const _default: React.ForwardRefExoticComponent<import("./AvatarBase").AvatarBaseProps & {
19
- /**
20
- * Avatar style variant\
21
- * Allowed variants: `circular`, 'rounded' or `square`\
22
- * \
23
- * **Default**: `circular`
24
- */
25
- readonly variant?: "square" | "circular" | "rounded" | undefined;
26
- /**
27
- * Avatar size variant\
28
- * \
29
- * **Default**: `2.5em`
30
- */
31
- readonly size?: string | undefined;
32
- } & React.RefAttributes<HTMLSpanElement>>;
2
+ import { AvatarBaseProps } from './AvatarBase';
3
+ export type AvatarProps = AvatarBaseProps;
4
+ declare const _default: React.ForwardRefExoticComponent<AvatarBaseProps & React.RefAttributes<HTMLSpanElement>>;
33
5
  export default _default;
package/Avatar/index.js CHANGED
@@ -1,9 +1,95 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
17
  const react_1 = __importDefault(require("react"));
7
- const AvatarStandard_1 = __importDefault(require("./AvatarStandard"));
8
- const Avatar = (props, ref) => (react_1.default.createElement(AvatarStandard_1.default, Object.assign({}, props, { ref: ref })));
18
+ const styled_1 = __importDefault(require("@emotion/styled"));
19
+ const react_2 = require("@emotion/react");
20
+ const Color_1 = __importDefault(require("../Color"));
21
+ const AvatarBase_1 = __importDefault(require("./AvatarBase"));
22
+ const StyledAvatarBase = (0, styled_1.default)(AvatarBase_1.default) `
23
+ position: relative;
24
+ color: ${({ $color }) => $color.toString()};
25
+ background-color: ${({ $background }) => $background.toString()};
26
+ ${({ $background }) => {
27
+ switch (true) {
28
+ case $background.luminance() > 0.49:
29
+ return $background.darken(40).alpha(0.8).toString();
30
+ default:
31
+ return $background.darken(20).alpha(0.5).toString();
32
+ }
33
+ }};
34
+ &:hover {
35
+ background-color: ${({ $background, $clickable }) => $clickable && $background.darken(30).toString()};
36
+ }
37
+ &:focus-visible {
38
+ outline-color: ${({ theme, $background }) => $background.rgbString() === theme.color.accentPrimary.rgbString()
39
+ ? theme.color.textPrimary.toString()
40
+ : theme.color.accentPrimary.toString()};
41
+ }
42
+ ${({ $clickable }) => $clickable &&
43
+ (0, react_2.css) `
44
+ cursor: pointer;
45
+ `}
46
+ `;
47
+ const Avatar = (props, ref) => {
48
+ const { children, color, onClick, isOnline, size, src, variant = 'circular', alt, overrides } = props, restProps = __rest(props, ["children", "color", "onClick", "isOnline", "size", "src", "variant", "alt", "overrides"]);
49
+ const theme = (0, react_2.useTheme)();
50
+ const clickable = react_1.default.useMemo(() => typeof onClick === 'function', [onClick]);
51
+ const { $background, $color } = react_1.default.useMemo(() => {
52
+ switch (true) {
53
+ case color === 'primary':
54
+ return {
55
+ $color: theme.color.accentPrimaryContrast,
56
+ $background: theme.color.accentPrimary,
57
+ };
58
+ case color === 'secondary':
59
+ return {
60
+ $color: theme.color.accentSecondaryContrast,
61
+ $background: theme.color.accentSecondary,
62
+ };
63
+ case typeof color === 'undefined':
64
+ case color === 'default':
65
+ return {
66
+ $background: theme.color.surface.darken(10),
67
+ $color: theme.color.textPrimary,
68
+ };
69
+ case typeof color === 'string': {
70
+ let $background = theme.color.surface;
71
+ try {
72
+ if (color) {
73
+ $background = new Color_1.default(color);
74
+ }
75
+ }
76
+ catch (err) {
77
+ console.error(`invalid color value «${color}»`);
78
+ }
79
+ return {
80
+ $background,
81
+ $color: $background.contrast(theme.color.textPrimary) > 5
82
+ ? theme.color.textPrimary
83
+ : theme.color.surface,
84
+ };
85
+ }
86
+ default:
87
+ return {
88
+ $background: theme.color.surface,
89
+ $color: theme.color.textPrimary,
90
+ };
91
+ }
92
+ }, [color, theme.color]);
93
+ return (react_1.default.createElement(StyledAvatarBase, Object.assign({ "$clickable": clickable, "$color": $color, "$background": $background, color: color, onClick: onClick, size: size, src: src, variant: variant, alt: alt, tabIndex: clickable ? 0 : -1, ref: ref, overrides: overrides, isOnline: isOnline }, restProps), children));
94
+ };
9
95
  exports.default = react_1.default.forwardRef(Avatar);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@via-profit/ui-kit",
3
- "version": "0.1.0-rc.84",
3
+ "version": "0.1.0-rc.85",
4
4
  "description": "UI Kit",
5
5
  "repository": {
6
6
  "type": "git",