Skip to content

Commit 772c55d

Browse files
authored
LG-5623 feat: add variant to GalleryIndicator component (#3232)
* LG-5623 feat: add variant to GalleryIndicator component * cleanup, exported Variant
1 parent 9778d7b commit 772c55d

File tree

7 files changed

+71
-13
lines changed

7 files changed

+71
-13
lines changed

.changeset/sad-apes-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@leafygreen-ui/gallery-indicator': minor
3+
---
4+
5+
Add variant allowing user to pick between default and BaseGreen

packages/gallery-indicator/src/GalleryIndicator.stories.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@lg-tools/storybook-utils';
77
import { StoryFn } from '@storybook/react';
88

9-
import { GalleryIndicator } from '.';
9+
import { GalleryIndicator, Variant } from '.';
1010

1111
const meta: StoryMetaType<typeof GalleryIndicator> = {
1212
title: 'Components/Display/GalleryIndicator',
@@ -20,13 +20,15 @@ const meta: StoryMetaType<typeof GalleryIndicator> = {
2020
combineArgs: {
2121
darkMode: [false, true],
2222
activeIndex: [0, 1, 2, 3],
23+
variant: Object.values(Variant),
2324
},
2425
},
2526
},
2627
args: {
2728
activeIndex: 0,
2829
length: 4,
2930
darkMode: false,
31+
variant: Variant.Default,
3032
},
3133
argTypes: {
3234
darkMode: storybookArgTypes.darkMode,
@@ -42,6 +44,11 @@ const meta: StoryMetaType<typeof GalleryIndicator> = {
4244
max: 10,
4345
},
4446
},
47+
variant: {
48+
control: { type: 'select' },
49+
options: Object.values(Variant),
50+
defaultValue: Variant.Default,
51+
},
4552
},
4653
};
4754

packages/gallery-indicator/src/GalleryIndicator/GalleryIndicator.styles.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { css, cx } from '@leafygreen-ui/emotion';
22
import { Theme } from '@leafygreen-ui/lib';
33
import { palette } from '@leafygreen-ui/palette';
4-
import { color, spacing, transitionDuration } from '@leafygreen-ui/tokens';
4+
import { spacing, transitionDuration } from '@leafygreen-ui/tokens';
5+
6+
import { Variant } from './GalleryIndicator.types';
57

68
const TRANSITION_DURATION_SLOW = transitionDuration.slower;
79
const TRANSITION_DURATION_DEFAULT = transitionDuration.default;
@@ -25,23 +27,48 @@ export const getGalleryIndicatorStyles = ({
2527
className,
2628
);
2729

30+
const baseColorSet: Record<Theme, Record<Variant, string>> = {
31+
[Theme.Light]: {
32+
[Variant.Default]: palette.gray.light2,
33+
[Variant.BaseGreen]: palette.green.dark2,
34+
},
35+
[Theme.Dark]: {
36+
[Variant.Default]: palette.gray.dark2,
37+
[Variant.BaseGreen]: palette.green.light3,
38+
},
39+
};
40+
41+
const activeColorSet: Record<Theme, Record<Variant, string>> = {
42+
[Theme.Light]: {
43+
[Variant.Default]: palette.gray.base,
44+
[Variant.BaseGreen]: palette.green.base,
45+
},
46+
[Theme.Dark]: {
47+
[Variant.Default]: palette.gray.base,
48+
[Variant.BaseGreen]: palette.green.base,
49+
},
50+
};
51+
2852
export const getIndicatorStyles = ({
2953
theme,
3054
isActive,
55+
variant,
3156
}: {
3257
theme: Theme;
3358
isActive: boolean;
34-
}) =>
35-
cx(
59+
variant: Variant;
60+
}) => {
61+
const baseColor = baseColorSet[theme][variant];
62+
const activeColor = activeColorSet[theme][variant];
63+
64+
return cx(
3665
css`
3766
&::after {
3867
content: '';
3968
display: block;
4069
width: ${DOT_SIZE}px;
4170
height: ${DOT_SIZE}px;
42-
background-color: ${theme === Theme.Light
43-
? palette.gray.light2
44-
: palette.gray.dark2};
71+
background-color: ${baseColor};
4572
border-radius: 50%;
4673
transition-property: background-color, width, border-radius;
4774
transition-duration: ${TRANSITION_DURATION_SLOW}ms,
@@ -54,8 +81,9 @@ export const getIndicatorStyles = ({
5481
&::after {
5582
width: ${ACTIVE_DOT_SIZE}px;
5683
border-radius: 100px;
57-
background-color: ${color[theme].icon.secondary.default};
84+
background-color: ${activeColor};
5885
}
5986
`]: isActive,
6087
},
6188
);
89+
};

packages/gallery-indicator/src/GalleryIndicator/GalleryIndicator.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import {
88
getGalleryIndicatorStyles,
99
getIndicatorStyles,
1010
} from './GalleryIndicator.styles';
11-
import { GalleryIndicatorProps } from './GalleryIndicator.types';
11+
import { GalleryIndicatorProps, Variant } from './GalleryIndicator.types';
1212

13+
/**
14+
* GalleryIndicator is a component that displays a series of dots to indicate the current active index in a gallery.
15+
*/
1316
export const GalleryIndicator = React.forwardRef<
1417
HTMLUListElement,
1518
GalleryIndicatorProps
@@ -20,6 +23,7 @@ export const GalleryIndicator = React.forwardRef<
2023
length,
2124
activeIndex,
2225
className,
26+
variant = Variant.Default,
2327
'data-lgid': dataLgId,
2428
...rest
2529
}: GalleryIndicatorProps,
@@ -43,7 +47,7 @@ export const GalleryIndicator = React.forwardRef<
4347
key={i}
4448
data-testid={lgIds.indicator}
4549
data-lgid={lgIds.indicator}
46-
className={getIndicatorStyles({ theme, isActive })}
50+
className={getIndicatorStyles({ theme, isActive, variant })}
4751
data-active={isActive}
4852
/>
4953
);

packages/gallery-indicator/src/GalleryIndicator/GalleryIndicator.types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,17 @@ export interface GalleryIndicatorProps
1515
* The index of the active dot`
1616
*/
1717
activeIndex: number;
18+
19+
/**
20+
* The GalleryIndicator's style variant
21+
*
22+
* @default 'default'
23+
*/
24+
variant?: Variant;
1825
}
26+
27+
export const Variant = {
28+
Default: 'default',
29+
BaseGreen: 'baseGreen',
30+
} as const;
31+
export type Variant = (typeof Variant)[keyof typeof Variant];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { GalleryIndicator } from './GalleryIndicator';
2-
export { type GalleryIndicatorProps } from './GalleryIndicator.types';
2+
export { type GalleryIndicatorProps, Variant } from './GalleryIndicator.types';
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
export { GalleryIndicator } from './GalleryIndicator';
12
export {
2-
GalleryIndicator,
33
type GalleryIndicatorProps,
4-
} from './GalleryIndicator';
4+
Variant,
5+
} from './GalleryIndicator/GalleryIndicator.types';
56
export { DEFAULT_LGID_ROOT, getLgIds } from './utils';

0 commit comments

Comments
 (0)