@lumx/react 2.2.0 → 2.2.1-alpha.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.
@@ -1,20 +1,22 @@
1
+ import React from 'react';
2
+ import { select } from '@storybook/addon-knobs';
3
+
1
4
  import { mdiDelete, mdiEye, mdiPencil, mdiStar } from '@lumx/icons';
2
- import { AvatarSize, Badge, ColorPalette, Emphasis, Icon, IconButton, Size } from '@lumx/react';
5
+ import { Badge, ColorPalette, FlexBox, Icon, IconButton, Size } from '@lumx/react';
3
6
  import { AVATAR_IMAGES, avatarImageKnob, PORTRAIT_IMAGES } from '@lumx/react/stories/knobs/image';
4
- import { select } from '@storybook/addon-knobs';
5
- import React from 'react';
7
+ import { CustomLink } from '@lumx/react/stories/utils/CustomLink';
6
8
 
7
9
  import { Avatar } from './Avatar';
8
10
 
9
11
  export default { title: 'LumX components/avatar/Avatar' };
10
12
 
11
- const AVATAR_SIZES: AvatarSize[] = [Size.xs, Size.s, Size.m, Size.l, Size.xl, Size.xxl];
13
+ const AVATAR_SIZES = [Size.xs, Size.s, Size.m, Size.l, Size.xl, Size.xxl];
12
14
 
13
15
  /**
14
16
  * Avatar stories showing a simple Avatar with different sizes.
15
17
  * @return component with different sizes.
16
18
  */
17
- export const AvatarSizes = () =>
19
+ export const Sizes = () =>
18
20
  AVATAR_SIZES.map((size) => (
19
21
  <Avatar
20
22
  key={size}
@@ -29,7 +31,7 @@ export const AvatarSizes = () =>
29
31
  * Avatar story showing a simple avatar with different actions.
30
32
  * @return component with different actions.
31
33
  */
32
- export const AvatarWithActions = () =>
34
+ export const WithActions = () =>
33
35
  AVATAR_SIZES.map((size) => (
34
36
  <Avatar
35
37
  key={size}
@@ -37,45 +39,16 @@ export const AvatarWithActions = () =>
37
39
  alt={size}
38
40
  size={size}
39
41
  actions={
40
- <div style={{ display: 'flex', justifyContent: 'center' }}>
41
- <div className="lumx-spacing-margin-right-regular">
42
- <IconButton
43
- label="Edit"
44
- color="dark"
45
- emphasis={Emphasis.low}
46
- hasBackground
47
- icon={mdiPencil}
48
- size={Size.s}
49
- />
50
- </div>
51
-
52
- <div className="lumx-spacing-margin-right-regular">
53
- <IconButton
54
- label="See"
55
- color="dark"
56
- emphasis={Emphasis.low}
57
- hasBackground
58
- icon={mdiEye}
59
- size={Size.s}
60
- />
61
- </div>
62
-
63
- <div>
64
- <IconButton
65
- label="Delete"
66
- color="dark"
67
- emphasis={Emphasis.low}
68
- hasBackground
69
- icon={mdiDelete}
70
- size={Size.s}
71
- />
72
- </div>
73
- </div>
42
+ <FlexBox orientation="horizontal" gap="regular" vAlign="center">
43
+ <IconButton label="Edit" emphasis="low" hasBackground icon={mdiPencil} size="s" />
44
+ <IconButton label="See" emphasis="low" hasBackground icon={mdiEye} size="s" />
45
+ <IconButton label="Delete" emphasis="low" hasBackground icon={mdiDelete} size="s" />
46
+ </FlexBox>
74
47
  }
75
48
  />
76
49
  ));
77
50
 
78
- export const AvatarWithBadge = () =>
51
+ export const WithBadge = () =>
79
52
  AVATAR_SIZES.map((size) => (
80
53
  <Avatar
81
54
  key={size}
@@ -91,7 +64,7 @@ export const AvatarWithBadge = () =>
91
64
  />
92
65
  ));
93
66
 
94
- export const AvatarWithRectangularImage = () =>
67
+ export const WithRectangularImage = () =>
95
68
  AVATAR_SIZES.map((size) => (
96
69
  <Avatar
97
70
  key={size}
@@ -102,14 +75,18 @@ export const AvatarWithRectangularImage = () =>
102
75
  />
103
76
  ));
104
77
 
105
- export const AvatarClickable = () =>
106
- AVATAR_SIZES.map((size) => (
107
- <Avatar
108
- key={size}
109
- className="lumx-spacing-margin-bottom"
110
- image={AVATAR_IMAGES.avatar2}
111
- alt={size}
112
- size={size}
113
- onClick={() => alert('clicked on avatar')}
114
- />
115
- ));
78
+ export const Clickable = () => {
79
+ const baseProps = { size: 'l', image: AVATAR_IMAGES.avatar2, alt: 'avatar2' } as any;
80
+ return (
81
+ <>
82
+ <p>As a button</p>
83
+ <Avatar {...baseProps} onClick={() => alert('clicked on avatar')} />
84
+
85
+ <p>As a link</p>
86
+ <Avatar {...baseProps} linkProps={{ href: 'https://example.com' }} />
87
+
88
+ <p>As a custom link component</p>
89
+ <Avatar {...baseProps} linkAs={CustomLink} />
90
+ </>
91
+ );
92
+ };
@@ -23,6 +23,10 @@ export interface AvatarProps extends GenericProps {
23
23
  badge?: ReactElement;
24
24
  /** Image URL. */
25
25
  image: string;
26
+ /** Props to pass to the link wrapping the thumbnail. */
27
+ linkProps?: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
28
+ /** Custom react component for the link (can be used to inject react router Link). */
29
+ linkAs?: 'a' | any;
26
30
  /** On click callback. */
27
31
  onClick?: MouseEventHandler<HTMLDivElement>;
28
32
  /** On key press callback. */
@@ -70,6 +74,8 @@ export const Avatar: Comp<AvatarProps, HTMLDivElement> = forwardRef((props, ref)
70
74
  badge,
71
75
  className,
72
76
  image,
77
+ linkProps,
78
+ linkAs,
73
79
  onClick,
74
80
  onKeyPress,
75
81
  size,
@@ -85,6 +91,8 @@ export const Avatar: Comp<AvatarProps, HTMLDivElement> = forwardRef((props, ref)
85
91
  className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, size, theme }))}
86
92
  >
87
93
  <Thumbnail
94
+ linkProps={linkProps}
95
+ linkAs={linkAs}
88
96
  className={`${CLASSNAME}__thumbnail`}
89
97
  onClick={onClick}
90
98
  onKeyPress={onKeyPress}