feat: record group chevron button (#9645)

This ticket is related to this Discord post
https://discord.com/channels/1130383047699738754/1328756649657110559
This commit is contained in:
Jérémy M
2025-01-16 10:03:05 +01:00
committed by GitHub
parent f077efd171
commit f5b0926b63
8 changed files with 279 additions and 21 deletions

View File

@ -0,0 +1,129 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconComponent } from '@ui/display';
import {
LightIconButtonAccent,
LightIconButtonSize,
} from '@ui/input/button/components/LightIconButton';
import { motion, MotionProps } from 'framer-motion';
import { ComponentProps, MouseEvent } from 'react';
export type AnimatedLightIconButtonProps = {
className?: string;
testId?: string;
Icon?: IconComponent;
title?: string;
size?: LightIconButtonSize;
accent?: LightIconButtonAccent;
active?: boolean;
disabled?: boolean;
focus?: boolean;
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
} & Pick<ComponentProps<'button'>, 'aria-label' | 'title'> &
Pick<MotionProps, 'animate' | 'transition'>;
const StyledButton = styled.button<
Pick<AnimatedLightIconButtonProps, 'accent' | 'active' | 'size' | 'focus'>
>`
align-items: center;
background: transparent;
border: none;
border: ${({ disabled, theme, focus }) =>
!disabled && focus ? `1px solid ${theme.color.blue}` : 'none'};
border-radius: ${({ theme }) => theme.border.radius.sm};
box-shadow: ${({ disabled, theme, focus }) =>
!disabled && focus ? `0 0 0 3px ${theme.color.blue10}` : 'none'};
color: ${({ theme, accent, active, disabled, focus }) => {
switch (accent) {
case 'secondary':
return active || focus
? theme.color.blue
: !disabled
? theme.font.color.secondary
: theme.font.color.extraLight;
case 'tertiary':
return active || focus
? theme.color.blue
: !disabled
? theme.font.color.tertiary
: theme.font.color.extraLight;
}
}};
cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};
display: flex;
flex-direction: row;
font-family: ${({ theme }) => theme.font.family};
font-weight: ${({ theme }) => theme.font.weight.regular};
gap: ${({ theme }) => theme.spacing(1)};
height: ${({ size }) => (size === 'small' ? '24px' : '32px')};
justify-content: center;
padding: ${({ theme }) => theme.spacing(1)};
transition: background 0.1s ease;
white-space: nowrap;
width: ${({ size }) => (size === 'small' ? '24px' : '32px')};
min-width: ${({ size }) => (size === 'small' ? '24px' : '32px')};
&:hover {
background: ${({ theme, disabled }) =>
!disabled ? theme.background.transparent.light : 'transparent'};
}
&:focus {
outline: none;
}
&:active {
background: ${({ theme, disabled }) =>
!disabled ? theme.background.transparent.medium : 'transparent'};
}
`;
const StyledIconContainer = styled(motion.div)`
display: flex;
align-items: center;
justify-content: center;
`;
export const AnimatedLightIconButton = ({
'aria-label': ariaLabel,
className,
testId,
animate,
transition,
Icon,
active = false,
size = 'small',
accent = 'secondary',
disabled = false,
focus = false,
onClick,
title,
}: AnimatedLightIconButtonProps) => {
const theme = useTheme();
return (
<StyledButton
data-testid={testId}
aria-label={ariaLabel}
onClick={onClick}
disabled={disabled}
focus={focus && !disabled}
accent={accent}
className={className}
size={size}
active={active}
title={title}
>
<StyledIconContainer animate={animate} transition={transition}>
{Icon && (
<Icon
size={size === 'medium' ? theme.icon.size.md : theme.icon.size.sm}
/>
)}
</StyledIconContainer>
</StyledButton>
);
};

View File

@ -92,6 +92,7 @@ export const LightIconButton = ({
title,
}: LightIconButtonProps) => {
const theme = useTheme();
return (
<StyledButton
data-testid={testId}

View File

@ -0,0 +1,108 @@
import { Meta, StoryObj } from '@storybook/react';
import { IconSearch } from '@ui/display';
import {
LightIconButtonAccent,
LightIconButtonSize,
} from '@ui/input/button/components/LightIconButton';
import {
CatalogDecorator,
CatalogStory,
ComponentDecorator,
} from '@ui/testing';
import { AnimatedLightIconButton } from '../AnimatedLightIconButton';
const meta: Meta<typeof AnimatedLightIconButton> = {
title: 'UI/Input/Button/AnimatedLightIconButton',
component: AnimatedLightIconButton,
};
export default meta;
type Story = StoryObj<typeof AnimatedLightIconButton>;
export const Default: Story = {
args: {
title: 'Filter',
accent: 'secondary',
disabled: false,
active: false,
focus: false,
Icon: IconSearch,
animate: { scale: 1.2 },
transition: { duration: 0.3 },
},
argTypes: {
Icon: { control: false },
animate: { control: 'object' },
transition: { control: 'object' },
},
decorators: [ComponentDecorator],
};
export const Catalog: CatalogStory<Story, typeof AnimatedLightIconButton> = {
args: {
title: 'Filter',
Icon: IconSearch,
animate: { scale: 1.2 },
transition: { duration: 0.3 },
},
argTypes: {
accent: { control: false },
disabled: { control: false },
active: { control: false },
focus: { control: false },
animate: { control: 'object' },
transition: { control: 'object' },
},
parameters: {
pseudo: { hover: ['.hover'], active: ['.pressed'] },
catalog: {
dimensions: [
{
name: 'states',
values: [
'default',
'hover',
'pressed',
'disabled',
'active',
'focus',
'disabled+focus',
'disabled+active',
],
props: (state: string) => {
switch (state) {
case 'default':
return {};
case 'hover':
case 'pressed':
return { className: state };
case 'focus':
return { focus: true };
case 'disabled':
return { disabled: true };
case 'active':
return { active: true };
case 'disabled+focus':
return { disabled: true, focus: true };
case 'disabled+active':
return { disabled: true, active: true };
default:
return {};
}
},
},
{
name: 'accents',
values: ['secondary', 'tertiary'] satisfies LightIconButtonAccent[],
props: (accent: LightIconButtonAccent) => ({ accent }),
},
{
name: 'sizes',
values: ['small', 'medium'] satisfies LightIconButtonSize[],
props: (size: LightIconButtonSize) => ({ size }),
},
],
},
},
decorators: [CatalogDecorator],
};