draft-components 2.4.2 → 2.5.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.
@@ -570,153 +570,83 @@
570
570
  }
571
571
 
572
572
  .dc-avatar {
573
- --dc-avatar-size: 40px;
574
- --dc-avatar-radius: 50%;
575
- --dc-avatar-font-size: 16px;
576
- --dc-avatar-color: var(--dc-white);
577
- --dc-avatar-bg: var(--dc-gray-400);
578
- --dc-avatar-image-border-color: rgb(var(--dc-gray-700-rgb) / 0.1);
573
+ --dc-avatar-monogram-color: var(--dc-white);
574
+ --dc-avatar-silhouette-color: var(--dc-white);
575
+ --dc-avatar-bg-color-1: #94a3b8;
576
+ --dc-avatar-bg-color-2: #64748b;
577
+ --dc-avatar-border-color: rgb(var(--dc-black-rgb) / 0.025);
579
578
 
580
- color-scheme: light;
581
- font-family: var(--dc-primary-font);
582
- font-size: var(--dc-avatar-font-size);
583
- font-weight: 600;
584
- line-height: 1;
585
- color: var(--dc-avatar-color);
586
- position: relative;
587
- display: inline-flex;
588
- overflow: hidden;
589
579
  -webkit-user-select: none;
590
- -moz-user-select: none;
591
- user-select: none;
592
- align-items: center;
593
- justify-content: center;
594
- width: var(--dc-avatar-size);
595
- height: var(--dc-avatar-size);
596
- border-radius: var(--dc-avatar-radius);
597
- background: var(--dc-avatar-bg);
598
- }
599
-
600
- .dc-avatar_image::after {
601
- content: '';
602
- position: absolute;
603
- top: 0;
604
- left: 0;
605
- box-sizing: border-box;
606
- width: 100%;
607
- height: 100%;
608
- border: 1px solid var(--dc-avatar-image-border-color);
609
- border-radius: inherit;
610
- }
611
-
612
- .dc-avatar_size_xs {
613
- --dc-avatar-size: 24px;
614
- --dc-avatar-font-size: 10px;
615
- }
616
580
 
617
- .dc-avatar_size_sm {
618
- --dc-avatar-size: 32px;
619
- --dc-avatar-font-size: 12px;
620
- }
621
-
622
- .dc-avatar_size_lg {
623
- --dc-avatar-size: 48px;
624
- --dc-avatar-font-size: 20px;
625
- }
626
-
627
- .dc-avatar_size_xl {
628
- --dc-avatar-size: 56px;
629
- --dc-avatar-font-size: 24px;
630
- }
631
-
632
- .dc-avatar_square {
633
- --dc-avatar-radius: 8px;
634
- }
635
-
636
- .dc-avatar_square.dc-avatar_size_xs {
637
- --dc-avatar-radius: 4px;
638
- }
639
-
640
- .dc-avatar_square.dc-avatar_size_sm {
641
- --dc-avatar-radius: 6px;
642
- }
581
+ -moz-user-select: none;
643
582
 
644
- .dc-avatar_square.dc-avatar_size_lg {
645
- --dc-avatar-radius: 9px;
583
+ user-select: none;
646
584
  }
647
585
 
648
- .dc-avatar_square.dc-avatar_size_xl {
649
- --dc-avatar-radius: 10px;
586
+ .dc-avatar_type_image {
587
+ --dc-avatar-border-color: rgb(var(--dc-black-rgb) / 0.1);
650
588
  }
651
589
 
652
590
  .dc-avatar_fill_pink {
653
- --dc-avatar-color: var(--dc-white);
654
- --dc-avatar-bg: #f472b6;
591
+ --dc-avatar-bg-color-1: #fb7185;
592
+ --dc-avatar-bg-color-2: #f43f5e;
655
593
  }
656
594
 
657
595
  .dc-avatar_fill_red {
658
- --dc-avatar-color: var(--dc-white);
659
- --dc-avatar-bg: #f87171;
596
+ --dc-avatar-bg-color-1: #f87171;
597
+ --dc-avatar-bg-color-2: #ef4444;
660
598
  }
661
599
 
662
600
  .dc-avatar_fill_orange {
663
- --dc-avatar-color: var(--dc-white);
664
- --dc-avatar-bg: #fb923c;
601
+ --dc-avatar-bg-color-1: #fb923c;
602
+ --dc-avatar-bg-color-2: #f97316;
665
603
  }
666
604
 
667
605
  .dc-avatar_fill_yellow {
668
- --dc-avatar-color: var(--dc-white);
669
- --dc-avatar-bg: #fbbf24;
606
+ --dc-avatar-bg-color-1: #fbbf24;
607
+ --dc-avatar-bg-color-2: #f59e0b;
670
608
  }
671
609
 
672
610
  .dc-avatar_fill_green {
673
- --dc-avatar-color: var(--dc-white);
674
- --dc-avatar-bg: #4ade80;
611
+ --dc-avatar-bg-color-1: #4ade80;
612
+ --dc-avatar-bg-color-2: #22c55e;
675
613
  }
676
614
 
677
615
  .dc-avatar_fill_teal {
678
- --dc-avatar-color: var(--dc-white);
679
- --dc-avatar-bg: #2dd4bf;
616
+ --dc-avatar-bg-color-1: #2dd4bf;
617
+ --dc-avatar-bg-color-2: #14b8a6;
680
618
  }
681
619
 
682
620
  .dc-avatar_fill_blue {
683
- --dc-avatar-color: var(--dc-white);
684
- --dc-avatar-bg: #60a5fa;
621
+ --dc-avatar-bg-color-1: #38bdf8;
622
+ --dc-avatar-bg-color-2: #0ea5e9;
685
623
  }
686
624
 
687
625
  .dc-avatar_fill_indigo {
688
- --dc-avatar-color: var(--dc-white);
689
- --dc-avatar-bg: #818cf8;
626
+ --dc-avatar-bg-color-1: #818cf8;
627
+ --dc-avatar-bg-color-2: #6366f1;
690
628
  }
691
629
 
692
630
  .dc-avatar_fill_violet {
693
- --dc-avatar-color: var(--dc-white);
694
- --dc-avatar-bg: #a78bfa;
631
+ --dc-avatar-bg-color-1: #c084fc;
632
+ --dc-avatar-bg-color-2: #a855f7;
695
633
  }
696
634
 
697
- .dc-avatar__image,
698
- .dc-avatar__silhouette {
699
- line-height: 1;
700
- width: 100%;
701
- height: 100%;
702
- border-radius: inherit;
703
- }
704
-
705
- .dc-avatar-group {
706
- --dc-avatar-in-group-stroke: var(--dc-primary-bg);
707
-
708
- color-scheme: light;
709
- display: inline-flex;
710
- align-items: center;
711
- box-sizing: border-box;
635
+ .dc-avatar__monogram {
636
+ font-family: var(--dc-primary-font);
637
+ font-size: 24px;
638
+ font-weight: 600;
639
+ letter-spacing: 0.025em;
640
+ fill: var(--dc-avatar-monogram-color);
712
641
  }
713
642
 
714
- .dc-avatar-group > .dc-avatar {
715
- box-shadow: 0 0 0 2px var(--dc-avatar-in-group-stroke);
643
+ .dc-avatar__silhouette {
644
+ fill: var(--dc-avatar-silhouette-color);
716
645
  }
717
646
 
718
- .dc-avatar-group > .dc-avatar:nth-child(n + 2) {
719
- margin-left: -10px;
647
+ .dc-avatar__border {
648
+ fill: none;
649
+ stroke: var(--dc-avatar-border-color);
720
650
  }
721
651
 
722
652
  .dc-button {
@@ -289,14 +289,14 @@
289
289
 
290
290
  .dark .dc-avatar,
291
291
  .dark.dc-avatar {
292
- --dc-avatar-image-border-color: rgb(var(--dc-gray-50-rgb) / 0.15);
292
+ --dc-avatar-border-color: rgb(var(--dc-white-rgb) / 0.025);
293
293
 
294
294
  color-scheme: dark;
295
295
  }
296
296
 
297
- .dark .dc-avatar-group,
298
- .dark.dc-avatar-group {
299
- color-scheme: dark;
297
+ .dark .dc-avatar_type_image,
298
+ .dark.dc-avatar_type_image {
299
+ --dc-avatar-border-color: rgb(var(--dc-white-rgb) / 0.1);
300
300
  }
301
301
 
302
302
  .dark .dc-button,
@@ -1,5 +1,6 @@
1
1
  import { ComponentPropsWithRef } from 'react';
2
- type AvatarHTMLProps = ComponentPropsWithRef<'div'>;
2
+ type AvatarHTMLProps = ComponentPropsWithRef<'svg'>;
3
+ type AvatarBaseProps = Omit<AvatarHTMLProps, 'fill'>;
3
4
  export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
4
5
  export type AvatarFill = 'gray' | 'pink' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'indigo' | 'violet';
5
6
  export type AvatarProps = {
@@ -8,7 +9,7 @@ export type AvatarProps = {
8
9
  fill?: AvatarFill;
9
10
  src?: string;
10
11
  altText?: string;
11
- initials?: string;
12
- } & AvatarHTMLProps;
13
- export declare const Avatar: import("react").ForwardRefExoticComponent<Omit<AvatarProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
12
+ monogram?: string;
13
+ } & AvatarBaseProps;
14
+ export declare const Avatar: import("react").ForwardRefExoticComponent<Omit<AvatarProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
14
15
  export {};
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useState } from 'react';
2
+ import { forwardRef, useId } from 'react';
3
3
  import { classNames } from '../../lib/react-helpers.js';
4
4
  const sizesInPixels = {
5
5
  xs: 24,
@@ -8,40 +8,32 @@ const sizesInPixels = {
8
8
  lg: 48,
9
9
  xl: 56,
10
10
  };
11
- export const Avatar = forwardRef(function Avatar({ square, size = 'md', fill = 'gray', src, altText, initials, className, ...props }, ref) {
11
+ export const Avatar = forwardRef(function Avatar({ square, size = 'md', fill = 'gray', src, altText, monogram, className, ...props }, ref) {
12
+ const id = useId();
13
+ const titleId = altText ? `${id}avatar-title` : undefined;
14
+ const maskId = `${id}avatar-mask`;
15
+ const gradientId = `${id}avatar-gradient`;
12
16
  const sizePx = sizesInPixels[size] ?? sizesInPixels.md;
13
- const [type, setType] = useState(() => {
14
- let type;
15
- if (src) {
16
- type = 'image';
17
- }
18
- else if (initials) {
19
- type = 'initials';
20
- }
21
- else {
22
- type = 'silhouette';
23
- }
24
- return type;
25
- });
26
17
  let children;
27
- if (type === 'image') {
28
- children = (_jsx("img", { className: "dc-avatar__image", src: src, width: sizePx, height: sizePx, alt: "", loading: "lazy", onLoad: (event) => {
29
- if (altText) {
30
- event.currentTarget.setAttribute('alt', altText);
31
- }
32
- }, onError: () => {
33
- setType(initials ? 'initials' : 'silhouette');
34
- } }));
18
+ let type;
19
+ if (src) {
20
+ type = 'image';
21
+ children = (_jsx("image", { href: src, width: "100%", height: "100%", preserveAspectRatio: "xMidYMid slice" }));
35
22
  }
36
- else if (type === 'initials') {
37
- children = (_jsx("span", { className: "dc-avatar__initials", "aria-label": altText, children: initials }));
23
+ else if (monogram) {
24
+ type = 'monogram';
25
+ children = (_jsx("text", { className: "dc-avatar__monogram", x: "28", y: "28", dy: "5%", textAnchor: "middle", dominantBaseline: "middle", children: monogram.slice(0, 2) }));
38
26
  }
39
27
  else {
40
- children = (_jsxs("svg", { className: "dc-avatar__silhouette", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 56 56", width: sizePx, height: sizePx, fill: "none", children: [altText ? _jsx("title", { children: altText }) : null, square ? (_jsx("path", { fill: "white", fillRule: "evenodd", clipRule: "evenodd", d: "M28.0001 29.5957C33.3078 29.5957 37.6106 24.9852 37.6106 19.2979C37.6106 13.6105 33.3078 9 28.0001 9C22.6923 9 18.3895 13.6105 18.3895 19.2979C18.3895 24.9852 22.6923 29.5957 28.0001 29.5957ZM7.03967 49.4839C6.71299 51.4741 8.45242 53 10.4693 53H45.5305C47.5474 53 49.2868 51.4741 48.9601 49.4839C47.6918 41.7571 39.6459 33.3404 27.9999 33.3404C16.3538 33.3404 8.30794 41.7571 7.03967 49.4839Z" })) : (_jsx("path", { fill: "white", fillRule: "evenodd", clipRule: "evenodd", d: "M9.28643 44.5776C12.6548 39.0053 19.3297 34.3404 27.9999 34.3404C36.6702 34.3404 43.3451 39.0054 46.7134 44.5777C42.1335 49.7439 35.447 53 28 53C20.5529 53 13.8664 49.7438 9.28643 44.5776ZM37.6106 20.2979C37.6106 25.9852 33.3078 30.5957 28.0001 30.5957C22.6923 30.5957 18.3895 25.9852 18.3895 20.2979C18.3895 14.6105 22.6923 10 28.0001 10C33.3078 10 37.6106 14.6105 37.6106 20.2979Z" }))] }));
28
+ type = 'silhouette';
29
+ children = square ? (_jsx("path", { className: "dc-avatar__silhouette", fillRule: "evenodd", clipRule: "evenodd", d: "M28.0001 29.5957C33.3078 29.5957 37.6106 24.9852 37.6106 19.2979C37.6106 13.6105 33.3078 9 28.0001 9C22.6923 9 18.3895 13.6105 18.3895 19.2979C18.3895 24.9852 22.6923 29.5957 28.0001 29.5957ZM7.03967 49.4839C6.71299 51.4741 8.45242 53 10.4693 53H45.5305C47.5474 53 49.2868 51.4741 48.9601 49.4839C47.6918 41.7571 39.6459 33.3404 27.9999 33.3404C16.3538 33.3404 8.30794 41.7571 7.03967 49.4839Z" })) : (_jsx("path", { className: "dc-avatar__silhouette", fillRule: "evenodd", clipRule: "evenodd", d: "M9.28643 44.5776C12.6548 39.0053 19.3297 34.3404 27.9999 34.3404C36.6702 34.3404 43.3451 39.0054 46.7134 44.5777C42.1335 49.7439 35.447 53 28 53C20.5529 53 13.8664 49.7438 9.28643 44.5776ZM37.6106 20.2979C37.6106 25.9852 33.3078 30.5957 28.0001 30.5957C22.6923 30.5957 18.3895 25.9852 18.3895 20.2979C18.3895 14.6105 22.6923 10 28.0001 10C33.3078 10 37.6106 14.6105 37.6106 20.2979Z" }));
41
30
  }
42
- return (_jsx("div", { ref: ref, "data-size": size, "data-fill": size, className: classNames(className, 'dc-avatar', `dc-avatar_${type}`, {
43
- [`dc-avatar_size_${size}`]: size,
31
+ const maskElement = square
32
+ ? _jsx("rect", { width: "56", height: "56", rx: "10", fill: "#fff" })
33
+ : _jsx("circle", { r: "28", cx: "28", cy: "28", fill: "#fff" });
34
+ return (_jsxs("svg", { ref: ref, className: classNames(className, {
35
+ 'dc-avatar': true,
36
+ [`dc-avatar_type_${type}`]: type,
44
37
  [`dc-avatar_fill_${fill}`]: fill,
45
- 'dc-avatar_square': square,
46
- }), ...props, children: children }));
38
+ }), xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 56 56", width: sizePx, height: sizePx, role: "img", "aria-labelledby": titleId, ...props, children: [altText ? _jsx("title", { id: titleId, children: altText }) : null, _jsxs("defs", { children: [_jsx("mask", { id: maskId, children: maskElement }), _jsxs("linearGradient", { id: gradientId, x1: "0", x2: "0", y1: "0", y2: "1", children: [_jsx("stop", { stopColor: "var(--dc-avatar-bg-color-1)", offset: "0%" }), _jsx("stop", { stopColor: "var(--dc-avatar-bg-color-2)", offset: "100%" })] })] }), _jsxs("g", { mask: `url(#${maskId})`, children: [_jsx("rect", { fill: `url(#${gradientId})`, width: "56", height: "56" }), children, _jsx(maskElement.type, { ...maskElement.props, className: "dc-avatar__border", strokeWidth: "3" })] })] }));
47
39
  });
@@ -1,6 +1,5 @@
1
1
  export * from './alert/index.js';
2
2
  export * from './avatar/index.js';
3
- export * from './avatar-group/index.js';
4
3
  export * from './badge/index.js';
5
4
  export * from './breadcrumbs/index.js';
6
5
  export * from './button/index.js';
@@ -1,6 +1,5 @@
1
1
  export * from './alert/index.js';
2
2
  export * from './avatar/index.js';
3
- export * from './avatar-group/index.js';
4
3
  export * from './badge/index.js';
5
4
  export * from './breadcrumbs/index.js';
6
5
  export * from './button/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draft-components",
3
- "version": "2.4.2",
3
+ "version": "2.5.0",
4
4
  "description": "The React based UI components library.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -10,6 +10,7 @@
10
10
  },
11
11
  "./css/*": "./css/*"
12
12
  },
13
+ "types": "./dist/index.d.ts",
13
14
  "engines": {
14
15
  "node": ">= 16"
15
16
  },
@@ -51,48 +52,50 @@
51
52
  "react-dom": ">= 18"
52
53
  },
53
54
  "devDependencies": {
54
- "@alexzimakov/eslint-config": "1.7.0",
55
+ "@alexzimakov/eslint-config": "1.8.0",
55
56
  "@heroicons/react": "2.0.18",
56
- "@storybook/addon-actions": "7.4.6",
57
- "@storybook/addon-essentials": "7.4.6",
58
- "@storybook/addon-links": "7.4.6",
59
- "@storybook/addon-themes": "7.4.6",
60
- "@storybook/react": "7.4.6",
61
- "@storybook/react-vite": "7.4.6",
57
+ "@storybook/addon-actions": "7.5.3",
58
+ "@storybook/addon-essentials": "7.5.3",
59
+ "@storybook/addon-links": "7.5.3",
60
+ "@storybook/addon-themes": "7.5.3",
61
+ "@storybook/react": "7.5.3",
62
+ "@storybook/react-vite": "7.5.3",
62
63
  "@testing-library/dom": "9.3.3",
63
64
  "@testing-library/jest-dom": "6.1.4",
64
65
  "@testing-library/react": "14.0.0",
65
66
  "@testing-library/user-event": "14.5.1",
66
- "@types/node": "18.18.5",
67
- "@types/react": "18.2.28",
68
- "@types/react-dom": "18.2.13",
69
- "@typescript-eslint/eslint-plugin": "6.7.5",
70
- "@typescript-eslint/parser": "6.7.5",
67
+ "@types/node": "20.9.0",
68
+ "@types/react": "18.2.37",
69
+ "@types/react-dom": "18.2.15",
70
+ "@typescript-eslint/eslint-plugin": "6.10.0",
71
71
  "@vitest/coverage-istanbul": "0.34.6",
72
72
  "autoprefixer": "10.4.16",
73
- "eslint": "8.51.0",
74
- "eslint-plugin-jsx-a11y": "6.7.1",
73
+ "eslint": "8.53.0",
74
+ "eslint-plugin-jsx-a11y": "6.8.0",
75
75
  "eslint-plugin-react": "7.33.2",
76
76
  "eslint-plugin-react-hooks": "4.6.0",
77
77
  "eslint-plugin-storybook": "0.6.15",
78
78
  "eslint-plugin-testing-library": "6.1.0",
79
79
  "husky": "8.0.3",
80
80
  "jsdom": "22.1.0",
81
- "lint-staged": "15.0.1",
81
+ "lint-staged": "15.0.2",
82
82
  "postcss": "8.4.31",
83
83
  "postcss-import": "15.1.0",
84
84
  "react": "18.2.0",
85
85
  "react-dom": "18.2.0",
86
- "storybook": "7.4.6",
87
- "stylelint": "15.10.3",
86
+ "storybook": "7.5.3",
87
+ "stylelint": "15.11.0",
88
88
  "stylelint-config-standard": "34.0.0",
89
89
  "stylelint-order": "6.0.3",
90
90
  "typescript": "5.2.2",
91
- "vite": "4.4.11",
91
+ "vite": "4.5.0",
92
92
  "vitest": "0.34.6"
93
93
  },
94
94
  "lint-staged": {
95
95
  "*.ts?(x)": "npm run lint-js",
96
96
  "*.css": "npm run lint-css"
97
+ },
98
+ "dependencies": {
99
+ "@typescript-eslint/parser": "6.10.0"
97
100
  }
98
101
  }
@@ -1,7 +0,0 @@
1
- import { ComponentPropsWithoutRef, JSX } from 'react';
2
- type AvatarGroupBaseProps = Omit<ComponentPropsWithoutRef<'div'>, 'children'>;
3
- export type AvatarGroupProps = AvatarGroupBaseProps & {
4
- children: JSX.Element | JSX.Element[];
5
- };
6
- export declare function AvatarGroup({ className, children, ...props }: AvatarGroupProps): import("react/jsx-runtime").JSX.Element;
7
- export {};
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { classNames } from '../../lib/react-helpers.js';
3
- export function AvatarGroup({ className, children, ...props }) {
4
- return (_jsx("div", { ...props, className: classNames(className, 'dc-avatar-group'), children: children }));
5
- }
@@ -1 +0,0 @@
1
- export * from './avatar-group.js';
@@ -1 +0,0 @@
1
- export * from './avatar-group.js';