@altinn/altinn-components 0.0.1 → 0.1.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.
@@ -0,0 +1,18 @@
1
+ .preview-container-stage-tag {
2
+ color: #fff;
3
+ position: absolute;
4
+ top: 1rem;
5
+ right: 1rem;
6
+ }
7
+
8
+ .preview-container-stage-tag[data-tag="experimental"] {
9
+ background-color: #f0ad4e;
10
+ padding: 0.25rem 0.5rem;
11
+ border-radius: 0.25rem;
12
+ }
13
+
14
+ .preview-container-stage-tag[data-tag="stable"] {
15
+ background-color: #5cb85c;
16
+ padding: 0.25rem 0.5rem;
17
+ border-radius: 0.25rem;
18
+ }
@@ -0,0 +1,33 @@
1
+ import "../lib/css/global.css";
2
+ import "./preview.css";
3
+ import {StoryFn} from "@storybook/react";
4
+
5
+ /** @type { import('@storybook/react').Preview } */
6
+ const preview = {
7
+ parameters: {
8
+ controls: {
9
+ matchers: {
10
+ color: /(background|color)$/i,
11
+ date: /Date$/i,
12
+ },
13
+ },
14
+ },
15
+ decorators: [
16
+ (Story: StoryFn, { tags }: { tags: string[]}) => {
17
+ const isStable = (tags || []).includes('stable');
18
+ const state = isStable ? 'stable' : 'experimental';
19
+ return (
20
+ <>
21
+ <span className='preview-container-stage-tag' data-tag={state}>
22
+ {state}
23
+ </span>
24
+ <Story />
25
+ </>
26
+ );
27
+ },
28
+ ],
29
+ };
30
+
31
+
32
+
33
+ export default preview;
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.0](https://github.com/Altinn/altinn-components/compare/v0.0.1...v0.1.0) (2024-11-01)
4
+
5
+
6
+ ### Features
7
+
8
+ * mark Avatar and AvatarGroup as stable ([#14](https://github.com/Altinn/altinn-components/issues/14)) ([fd8bbce](https://github.com/Altinn/altinn-components/commit/fd8bbce2ce59954d8682527b1a9d70bd08b9ccd7))
9
+
3
10
  ## 0.0.1 (2024-10-31)
4
11
 
5
12
 
@@ -6,8 +6,9 @@ import { fromStringToColor } from './color';
6
6
 
7
7
  export type AvatarType = 'company' | 'person' | 'custom';
8
8
  export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
9
- export type AvatarVariant = 'square' | 'circle';
10
- export type AvatarColor = 'dark' | 'light';
9
+
10
+ type AvatarVariant = 'square' | 'circle';
11
+ type AvatarColor = 'dark' | 'light';
11
12
 
12
13
  /**
13
14
  * Props for the Avatar component.
@@ -19,10 +20,6 @@ export interface AvatarProps {
19
20
  type?: AvatarType;
20
21
  /** The size of the avatar. */
21
22
  size?: AvatarSize;
22
- /** The variant of the avatar shape. */
23
- variant?: AvatarVariant;
24
- /** The color theme of the avatar. */
25
- color?: AvatarColor;
26
23
  /** Additional class names to apply to the avatar. */
27
24
  className?: string;
28
25
  /** URL of the image to display in the avatar. */
@@ -39,10 +36,8 @@ export interface AvatarProps {
39
36
  * Avatar component to display user or company avatars with various customization options.
40
37
  */
41
38
  export const Avatar = ({
42
- type,
39
+ type = 'person',
43
40
  size = 'sm',
44
- variant,
45
- color,
46
41
  name = 'Avatar',
47
42
  outline = false,
48
43
  imageUrl,
@@ -51,13 +46,10 @@ export const Avatar = ({
51
46
  className,
52
47
  }: AvatarProps): JSX.Element => {
53
48
  const [hasImageError, setHasImageError] = useState<boolean>(false);
49
+ const variant: AvatarVariant = type === 'person' ? 'circle' : 'square';
50
+ const color: AvatarColor = type === 'person' ? 'light' : 'dark';
54
51
 
55
- const defaultVariant = type === 'person' ? 'circle' : 'square';
56
- const defaultColor = type === 'person' ? 'light' : 'dark';
57
- const appliedVariant = variant || defaultVariant;
58
- const appliedColor = color || defaultColor;
59
-
60
- const { backgroundColor, foregroundColor } = fromStringToColor(name, appliedColor);
52
+ const { backgroundColor, foregroundColor } = fromStringToColor(name, color);
61
53
  const initials = (name[0] ?? '').toUpperCase();
62
54
  const usingImageUrl = imageUrl && !hasImageError;
63
55
 
@@ -70,7 +62,7 @@ export const Avatar = ({
70
62
 
71
63
  return (
72
64
  <div
73
- className={cx(styles.avatar, styles[appliedVariant], styles[size], { [styles.outline]: outline }, className)}
65
+ className={cx(styles.avatar, styles[variant], styles[size], { [styles.outline]: outline }, className)}
74
66
  style={inlineStyles}
75
67
  aria-hidden
76
68
  >
@@ -1,12 +1,11 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
- import { fn } from '@storybook/test';
3
2
  import { AvatarGroup } from './AvatarGroup';
4
3
 
5
4
  const meta = {
6
5
  title: 'Avatar/AvatarGroup',
7
6
  component: AvatarGroup,
8
7
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
9
- tags: ['autodocs'],
8
+ tags: ['autodocs', 'stable'],
10
9
  parameters: {
11
10
  // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
12
11
  // layout: 'fullscreen',
@@ -19,7 +18,7 @@ type Story = StoryObj<typeof meta>;
19
18
 
20
19
  export const People: Story = {
21
20
  args: {
22
- type: 'person',
21
+ defaultType: 'person',
23
22
  items: [
24
23
  {
25
24
  name: 'Albert Åberg',
@@ -36,7 +35,7 @@ export const People: Story = {
36
35
 
37
36
  export const Companies: Story = {
38
37
  args: {
39
- type: 'company',
38
+ defaultType: 'company',
40
39
  items: [
41
40
  {
42
41
  name: 'Albert Åberg',
@@ -3,15 +3,32 @@ import { useMemo } from 'react';
3
3
  import { Avatar, type AvatarProps, type AvatarSize, type AvatarType } from '.';
4
4
  import styles from './avatarGroup.module.css';
5
5
 
6
+ /**
7
+ * Props for the AvatarGroup components.
8
+ */
6
9
  export interface AvatarGroupProps {
10
+ /** Array of avatars to display in the group, each specified by AvatarProps. */
7
11
  items?: AvatarProps[];
12
+ /** Maximum number of avatars to show in the group. Remaining avatars are summarized in a "+X" label. */
8
13
  maxItemsCount?: number;
9
- type?: AvatarType;
14
+ /** Default avatar type to apply if not specified in individual items. This affects the styling. */
15
+ defaultType?: AvatarType;
16
+ /** Size of all avatars in the group (e.g., 'sm', 'md', 'lg'). */
10
17
  size?: AvatarSize;
18
+ /** Additional CSS class for styling the avatar group container. */
11
19
  className?: string;
12
20
  }
13
21
 
14
- export const AvatarGroup = ({ items = [], maxItemsCount = 4, type, size = 'sm', className }: AvatarGroupProps) => {
22
+ /**
23
+ * Avatar group component for displaying multiple avatars as a group.
24
+ */
25
+ export const AvatarGroup = ({
26
+ items = [],
27
+ maxItemsCount = 4,
28
+ defaultType,
29
+ size = 'sm',
30
+ className,
31
+ }: AvatarGroupProps) => {
15
32
  const maxItems = useMemo(() => items.slice(0, maxItemsCount), [items, maxItemsCount]);
16
33
 
17
34
  if (items?.length === 0) {
@@ -30,7 +47,7 @@ export const AvatarGroup = ({ items = [], maxItemsCount = 4, type, size = 'sm',
30
47
  customLabel={customLabel}
31
48
  imageUrl={avatar.imageUrl}
32
49
  imageUrlAlt={avatar.imageUrlAlt}
33
- type={avatar?.type || type}
50
+ type={avatar?.type || defaultType}
34
51
  size={size}
35
52
  outline
36
53
  />
@@ -4,13 +4,11 @@ import { Avatar } from './';
4
4
  const meta = {
5
5
  title: 'Avatar/Avatar',
6
6
  component: Avatar,
7
- tags: ['autodocs'],
7
+ tags: ['autodocs', 'stable'],
8
8
  parameters: {},
9
9
  args: {
10
10
  name: 'Jane Doe',
11
11
  type: 'person',
12
- variant: 'circle',
13
- color: 'light',
14
12
  size: 'xl',
15
13
  },
16
14
  } satisfies Meta<typeof Avatar>;
@@ -30,15 +28,12 @@ export const Company: Story = {
30
28
  args: {
31
29
  type: 'company',
32
30
  name: 'Boligeksperten',
33
- variant: 'square',
34
31
  },
35
32
  };
36
33
 
37
34
  export const Logo: Story = {
38
35
  args: {
39
- variant: 'square',
40
36
  imageUrl: 'https://avatars.githubusercontent.com/u/1536293?s=200&v=4',
41
37
  size: 'xl',
42
- color: 'dark',
43
38
  },
44
39
  };
@@ -1,6 +1,4 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
- import { fn } from '@storybook/test';
3
-
4
2
  import { MenuItem } from './MenuItem';
5
3
 
6
4
  const meta = {
@@ -83,8 +81,8 @@ export const PersonGroup: Story = {
83
81
  export const Company: Story = {
84
82
  args: {
85
83
  avatar: {
86
- type: 'company',
87
84
  name: 'Sportsklubben Brann',
85
+ type: 'company',
88
86
  },
89
87
  title: 'Sportsklubben Brann',
90
88
  },
@@ -93,7 +91,7 @@ export const Company: Story = {
93
91
  export const CompanyGroup: Story = {
94
92
  args: {
95
93
  avatarGroup: {
96
- type: 'company',
94
+ defaultType: 'company',
97
95
  items: [
98
96
  {
99
97
  name: 'Sportsklubben Brann',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altinn/altinn-components",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "main": "lib/index.ts",
5
5
  "description": "Reusable react components",
6
6
  "publishConfig": {
package/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "local>Altinn/renovate-config"
5
+ ]
6
+ }
@@ -1,15 +0,0 @@
1
- import "../lib/css/global.css";
2
-
3
- /** @type { import('@storybook/react').Preview } */
4
- const preview = {
5
- parameters: {
6
- controls: {
7
- matchers: {
8
- color: /(background|color)$/i,
9
- date: /Date$/i,
10
- },
11
- },
12
- },
13
- };
14
-
15
- export default preview;