Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Button): add active animation #828

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 16 additions & 23 deletions src/components/_internal/BaseButton/BaseStyledButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ const ButtonSolid = css<BaseStyledButtonProps>`
outline: 4px solid ${(p) => getToken(`color-action-${p.$color}-focus`, p)};
}

&:active,
&.active {
background-color: ${(p) => getToken(`color-action-${p.$color}-active`, p)};
}

&:disabled,
&.disabled {
background-color: ${getToken(`color-action-background-disabled`)};
Expand All @@ -53,6 +48,8 @@ const ButtonOutline = css<BaseStyledButtonProps>`

&:hover,
&.hover {
background-color: ${(p) =>
getToken(`color-action-background-${p.$color}-active`, p)};
color: ${(p) => getToken(`color-action-${p.$color}-hover`, p)};
border-color: ${(p) => getToken(`color-action-${p.$color}-hover`, p)};
}
Expand All @@ -62,13 +59,6 @@ const ButtonOutline = css<BaseStyledButtonProps>`
border-color: ${(p) => getToken(`color-action-${p.$color}-hover`, p)};
outline: 4px solid ${(p) => getToken(`color-action-${p.$color}-focus`, p)};
}
&:active,
&.active {
background-color: ${(p) =>
getToken(`color-action-background-${p.$color}-active`, p)};
border-color: ${(p) => getToken(`color-action-${p.$color}-active`, p)};
color: ${(p) => getToken(`color-action-${p.$color}-active`, p)};
}

&:disabled,
&.disabled {
Expand Down Expand Up @@ -107,17 +97,6 @@ const ButtonText = css<BaseStyledButtonProps>`
outline: none;
}

&:active,
&&&.active {
color: ${(p) =>
getToken(
`color-action-${
p.$color === 'primary' || p.$color === 'secondary' ? 'link-' : ''
}${p.$color}-active`,
p,
)};
}

&:disabled,
&.disabled {
color: ${getToken(`color-action-text-disabled`)};
Expand All @@ -144,6 +123,8 @@ const BaseStyledButton = styled(Padbox).withConfig({
cursor: pointer;
text-align: center;
white-space: nowrap;
transition: all 300ms cubic-bezier(0.55, 0.085, 0.68, 0.53),
transform 50ms cubic-bezier(0.55, 0.085, 0.68, 0.53), outline 0ms;

${({ $margin }) => createMarginSpacing($margin)};
${({ $isExpanded }) => $isExpanded && 'width: 100%;'};
Expand All @@ -169,6 +150,18 @@ const BaseStyledButton = styled(Padbox).withConfig({
&:active {
text-decoration: none;
}

&:active,
&&&.active {
transform: scale(0.98);
}

@media (prefers-reduced-motion) {
&:active,
&&&.active {
transform: scale(1);
}
}
`;

export default BaseStyledButton;
2 changes: 1 addition & 1 deletion src/theme/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const createTokens = (
'color-action-secondary': colors.neutral[700],
'color-action-success': colors.success[700],
'color-action-danger': colors.error[500],
'color-action-primary-hover': colors.primary[700],
'color-action-primary-hover': colors.primary[800],
'color-action-secondary-hover': colors.neutral[900],
'color-action-success-hover': colors.success[800],
'color-action-danger-hover': colors.error[600],
Expand Down
Loading