Skip to content

Commit

Permalink
fix focus styling
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Feb 3, 2025
1 parent 2db65f8 commit 8da822e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
26 changes: 11 additions & 15 deletions src/components/CustomButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ const baseStyles = css`
align-items: center;
gap: 8px;
cursor: pointer;
border: none;
outline-offset: 1px;
&:disabled {
cursor: not-allowed;
}
&:focus-visible {
outline: 1px solid ${({ theme }) => theme.colors.lightPurpleBg};
outline-offset: 1px;
}
`;

const generateButtonStyles = (
Expand All @@ -56,24 +53,23 @@ const generateButtonStyles = (
},
}) => {
const buttonTheme = button[variant][theme];
const { background, text, border, hover, active, disabled } =
const { background, text, hover, focus, active, disabled } =
buttonTheme;
return css`
background-color: ${background};
border: 1px solid ${variant === "primary" ? background : border};
color: ${text};
&&& {
&&&& {
&:hover:not(:disabled) {
background-color: ${hover.background};
border-color: ${hover.background};
color: ${hover.text};
}
&:active:not(:disabled) {
background-color: ${hover.background};
border-color: ${active.background};
&:focus-visible:not(:disabled) {
background-color: ${focus.background};
outline: 1px solid ${focus.outline};
color: ${active.text};
}
Expand Down Expand Up @@ -101,14 +97,14 @@ const actionStyles = css`
padding: 6px 8px;
min-width: auto;
&&& {
&&&& {
&:hover:not(:disabled) {
color: ${action.hover.background};
}
&:active:not(:disabled) {
border: ${action.active.text};
color: ${action.active.text};
&:focus-visible:not(:disabled) {
outline: 1px solid ${action.focus.outline};
color: ${action.focus.text};
}
&:disabled {
Expand Down
22 changes: 16 additions & 6 deletions src/styles/theme/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const semanticColors = {
mediumBg: baseColors.dark.six,
grayBg: baseColors.gray.four,
darkBg: baseColors.dark.four,
darkActiveBg: baseColors.dark.one,
lightPurpleBg: baseColors.purple.one,
// text colors
lightBgText: baseColors.dark.one,
Expand Down Expand Up @@ -92,15 +93,17 @@ export const componentColors = {
background: baseColors.dark.five,
text: baseColors.gray.six,
hover: {
background: baseColors.dark.one,
background: semanticColors.darkActiveBg,
text: semanticColors.primaryPurple,
},
active: {
background: baseColors.dark.one,
background: semanticColors.darkActiveBg,
text: semanticColors.primaryPurple,
},
focus: {
outline: semanticColors.primaryPurple,
background: semanticColors.darkActiveBg,
outline: semanticColors.darkActiveBg,
text: semanticColors.primaryPurple,
},
disabled: {
background: baseColors.purple.three,
Expand All @@ -119,7 +122,9 @@ export const componentColors = {
text: semanticColors.lightBgActiveText,
},
focus: {
outline: semanticColors.primaryPurple,
background: semanticColors.activePurple,
outline: semanticColors.activePurple,
text: semanticColors.lightBgActiveText,
},
disabled: {
background: baseColors.gray.ten,
Expand All @@ -144,7 +149,9 @@ export const componentColors = {
// add border?
},
focus: {
outline: semanticColors.primaryPurple,
background: semanticColors.darkActiveBg,
outline: semanticColors.darkActiveBg,
text: semanticColors.primaryPurple,
},
disabled: {
background: baseColors.gray.three,
Expand All @@ -165,7 +172,9 @@ export const componentColors = {
text: semanticColors.lightBgActiveText,
},
focus: {
outline: semanticColors.primaryPurple,
background: semanticColors.activePurple,
outline: semanticColors.activePurple,
text: semanticColors.darkActiveBg,
},
disabled: {
background: semanticColors.transparentBg,
Expand All @@ -185,6 +194,7 @@ export const componentColors = {
},
focus: {
outline: semanticColors.activePurple,
text: semanticColors.activePurple,
},
disabled: {
text: baseColors.gray.eight,
Expand Down

0 comments on commit 8da822e

Please sign in to comment.