Skip to content

Commit 687dbde

Browse files
authored
Added hocus helper state variant to apply hover and focus (#20)
* Standardised focus behaviour * Added `hocus` helper state variant to apply `hover` and `focus` * Updated snapshot
1 parent 118d164 commit 687dbde

File tree

10 files changed

+31
-19
lines changed

10 files changed

+31
-19
lines changed

src/button/Button.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const Button = ({
3939
case 'fill':
4040
props.bg = brand ? theme.brandColors[brand] : bg
4141
props.text = brand ? theme.textColors.on[brand] : text
42-
props['bg-hover'] = getColorShade(
42+
props['bg-hocus'] = getColorShade(
4343
brand ? theme.brandColors[brand] : bg,
4444
theme.highlightOffset,
4545
)
@@ -48,22 +48,23 @@ const Button = ({
4848
// eslint-disable-next-line react/prop-types
4949
props.border.push(brand ? theme.brandColors[brand] : border)
5050
props.text = brand ? theme.brandColors[brand] : border
51-
props['bg-hover'] = brand ? theme.brandColors[brand] : border
52-
props['text-hover'] = brand ? theme.textColors.on[brand] : text
51+
props['bg-hocus'] = brand ? theme.brandColors[brand] : border
52+
props['text-hocus'] = brand ? theme.textColors.on[brand] : text
5353
break
5454
case 'text':
5555
props.text = brand ? theme.brandColors[brand] : text
56-
props['bg-hover'] = `${getColorShade(
56+
props['bg-hocus'] = `${getColorShade(
5757
brand ? theme.brandColors[brand] : text,
5858
'lightest',
5959
)}`
6060
break
6161
case 'link':
62-
props.leading = undefined
62+
props.rounded = undefined
63+
props.leading = 'normal'
6364
props.p = 0
6465
props.underline = true
6566
props.text = brand ? theme.brandColors[brand] : text
66-
props['text-hover'] = getColorShade(
67+
props['text-hocus'] = getColorShade(
6768
brand ? theme.brandColors[brand] : text,
6869
theme.highlightOffset,
6970
)

src/button/__tests__/__snapshots__/Button.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Button renders matching snapshot 1`] = `
44
<BaseComponent
55
bg="blue"
6-
bg-hover="blue-dark"
6+
bg-hocus="blue-dark"
77
border={
88
Array [
99
true,

src/form/TextInput.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ const TextInput = ({
3434
border={!isInvalid ? true : [true, theme.brandColors.danger]}
3535
w="full"
3636
leading="tight"
37-
outline-focus="none"
38-
shadow-focus="outline"
3937
opacity={disabled ? 50 : undefined}
4038
id={field.inputId || id || name}
4139
name={name}

src/form/__tests__/__snapshots__/TextInput.jsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ exports[`TextInput renders matching snapshot 1`] = `
1515
}
1616
}
1717
name="username"
18-
outline-focus="none"
1918
p={
2019
Object {
2120
"x": 4,
@@ -24,7 +23,6 @@ exports[`TextInput renders matching snapshot 1`] = `
2423
}
2524
readOnly={false}
2625
rounded="rounded"
27-
shadow-focus="outline"
2826
text="grey-darkest"
2927
type="text"
3028
w="full"

src/header/NavItem.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const NavItem = ({
1616
<BaseComponent
1717
is={is}
1818
text={style.text}
19-
bg-hover={style.text}
20-
text-hover={style.bg}
19+
bg-hocus={style.text}
20+
text-hocus={style.bg}
2121
p={{ x: theme.spacing.md, y: theme.spacing.sm }}
2222
m={{ t: theme.spacing.sm }}
2323
m-lg={{ t: 0, r: theme.spacing.sm }}

src/header/__tests__/__snapshots__/NavItem.jsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`NavItem renders matching snapshot 1`] = `
44
<BaseComponent
5-
bg-hover="white"
5+
bg-hocus="white"
66
className="block no-underline"
77
is={[Function]}
88
m={
@@ -24,7 +24,7 @@ exports[`NavItem renders matching snapshot 1`] = `
2424
}
2525
rounded="rounded"
2626
text="white"
27-
text-hover="blue"
27+
text-hocus="blue"
2828
>
2929
Link
3030
</BaseComponent>

src/header/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Example:
1919
<NavItem is={props => <a {...props} href="#header" />}>Docs</NavItem>
2020
<NavItem is={props => <a {...props} href="#header" />}>Examples</NavItem>
2121
<NavItem is={props => <a {...props} href="#header" />}>Blog</NavItem>
22-
<OutlineButton border="white" text="white" text-hover="blue">
22+
<OutlineButton border="white" text="white" text-hocus="blue">
2323
Download
2424
</OutlineButton>
2525
</NavMenu>
@@ -47,7 +47,7 @@ Custom branding example:
4747
<NavItem is={props => <a {...props} href="#header" />}>Docs</NavItem>
4848
<NavItem is={props => <a {...props} href="#header" />}>Examples</NavItem>
4949
<NavItem is={props => <a {...props} href="#header" />}>Blog</NavItem>
50-
<OutlineButton border="white" text="white" text-hover="purple">
50+
<OutlineButton border="white" text="white" text-hocus="purple">
5151
Download
5252
</OutlineButton>
5353
</NavMenu>

src/tailwind/BaseComponent.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ const BaseComponent = ({ is, children, className, ...rest }) => {
1313
return (
1414
<Component
1515
{...filterProps(rest, tailwindProps)}
16-
className={classnames(getTailwindClassNames(rest), className)}
16+
className={classnames(
17+
getTailwindClassNames({
18+
'outline-focus': 'none',
19+
'shadow-focus': 'outline',
20+
...rest,
21+
}),
22+
className,
23+
)}
1724
>
1825
{children}
1926
</Component>

src/tailwind/getTailwindClassNames.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ export default (props, { ignore = [] } = {}) =>
1414
if (!tailwindProps.includes(type)) return twClasses
1515

1616
if (tailwindVariants.includes(variant)) {
17+
if (variant === 'hocus') {
18+
return [
19+
...twClasses,
20+
tailwindPropToClassName(`hover:${type}`, props[key]),
21+
tailwindPropToClassName(`focus:${type}`, props[key]),
22+
]
23+
}
24+
1725
return [
1826
...twClasses,
1927
tailwindPropToClassName(`${variant}:${type}`, props[key]),

src/tailwind/tailwindProps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const propTypes = {
7171
whitespace: PropTypes.string,
7272
}
7373

74-
export const variants = ['hover', 'focus', 'sm', 'md', 'lg', 'xl']
74+
export const variants = ['hover', 'focus', 'hocus', 'sm', 'md', 'lg', 'xl']
7575

7676
export default [
7777
...Object.keys(propTypes),

0 commit comments

Comments
 (0)