Skip to content

Commit

Permalink
feat: Focus visible (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Mar 19, 2020
1 parent 374c279 commit 0801f28
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 70 deletions.
1 change: 1 addition & 0 deletions packages/fuselage-polyfills/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('focus-visible');
21 changes: 21 additions & 0 deletions packages/fuselage-polyfills/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@rocket.chat/fuselage-polyfills",
"version": "0.4.1",
"description": "A bundle of useful poly/ponyfills used by fuselage",
"author": {
"name": "Rocket.Chat",
"url": "https://rocket.chat/"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/RocketChat/Rocket.Chat.Fuselage.git"
},
"bugs": {
"url": "https://github.com/RocketChat/Rocket.Chat.Fuselage/issues"
},
"main": "index.js",
"dependencies": {
"focus-visible": "^5.0.2"
}
}
1 change: 1 addition & 0 deletions packages/fuselage/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ addDecorator(withTests({ results }));
configure(() => {
require('normalize.css/normalize.css');
require('@rocket.chat/icons/dist/rocketchat.css');
require('@rocket.chat/fuselage-polyfills');

if (process.env.NODE_ENV === 'loki') {
const style = document.createElement('style');
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@babel/preset-react": "^7.7.4",
"@rocket.chat/eslint-config": "^0.4.0",
"@rocket.chat/fuselage-hooks": "^0.4.1",
"@rocket.chat/fuselage-polyfills": "^0.4.1",
"@storybook/addon-actions": "5.2.8",
"@storybook/addon-backgrounds": "5.2.8",
"@storybook/addon-centered": "5.2.8",
Expand Down
12 changes: 6 additions & 6 deletions packages/fuselage/src/components/Button/stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Indicates an actionable user action.
default: {},
hover: { className: 'hover' },
active: { className: 'active' },
focus: { className: 'focus' },
'focus': { className: 'focus focus-visible' },
disabled: { disabled: true },
}}
/>
Expand All @@ -120,7 +120,7 @@ Indicates an actionable user action.
default: {},
hover: { className: 'hover' },
active: { className: 'active' },
focus: { className: 'focus' },
'focus': { className: 'focus focus-visible' },
disabled: { disabled: true },
}}
/>
Expand All @@ -142,7 +142,7 @@ Indicates an actionable user action.
default: {},
hover: { className: 'hover' },
active: { className: 'active' },
focus: { className: 'focus' },
'focus': { className: 'focus focus-visible' },
disabled: { disabled: true },
}}
/>
Expand All @@ -164,7 +164,7 @@ Indicates an actionable user action.
default: {},
hover: { className: 'hover' },
active: { className: 'active' },
focus: { className: 'focus' },
'focus': { className: 'focus focus-visible' },
disabled: { disabled: true },
}}
/>
Expand All @@ -186,7 +186,7 @@ Indicates an actionable user action.
default: {},
hover: { className: 'hover' },
active: { className: 'active' },
focus: { className: 'focus' },
'focus': { className: 'focus focus-visible' },
disabled: { disabled: true },
}}
/>
Expand All @@ -208,7 +208,7 @@ Indicates an actionable user action.
default: {},
hover: { className: 'hover' },
active: { className: 'active' },
focus: { className: 'focus' },
'focus': { className: 'focus focus-visible' },
disabled: { disabled: true },
}}
/>
Expand Down
50 changes: 1 addition & 49 deletions packages/fuselage/src/components/Button/styles.scss
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
@mixin button-with-colors(
$color,
$background-color,
$border-color,
$hover-background-color,
$hover-border-color,
$active-background-color,
$active-border-color,
$focus-background-color,
$focus-border-color,
$focus-shadow-color,
$disabled-color,
$disabled-background-color,
$disabled-border-color,
) {
color: $color;
border-color: $border-color;
background-color: $background-color;

&.focus,
&:focus {
border-color: $focus-border-color;
background-color: $focus-background-color;
@include use-focus-shadow($focus-shadow-color);
}

&.hover,
&:hover {
border-color: $hover-border-color;
background-color: $hover-background-color;
@include use-no-shadow;
}

&.active,
&:active {
border-color: $active-border-color;
background-color: $active-background-color;
@include use-no-shadow;
}

&.disabled,
&:disabled {
color: $disabled-color;
border-color: $disabled-border-color;
background-color: $disabled-background-color;
}
}

%button-secondary-color { // TODO: primitive atomic component
@include button-with-colors(
@include as-button (
$background-color: $button-colors-secondary-background-color,
$border-color: $button-colors-secondary-border-color,
$color: $button-colors-secondary-color,
Expand Down
24 changes: 13 additions & 11 deletions packages/fuselage/src/components/Tabs/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';

import { Box } from '../Box';

const Container = Box.extend('rcx-tabs');
const ItemsWrapper = Box.extend('rcx-tabs__wrapper');
const ScrollBox = Box.extend('rcx-tabs__scroll-box');
const ItemContainer = Box.extend('rcx-tabs__item', 'button');

export function Tabs({
children,
...props
}) {
return <Container {...props}>
<ScrollBox>
<ItemsWrapper children={children} role='tablist'/>
</ScrollBox>
</Container>;
return <Box is='div' componentClassName='rcx-tabs' {...props}>
<Box is='div' componentClassName='rcx-tabs__scroll-box'>
<Box is='div' componentClassName='rcx-tabs__wrapper' children={children} role='tablist'/>
</Box>
</Box>;
}

Tabs.displayName = 'Tabs';
Expand All @@ -24,7 +20,9 @@ export const TabsItem = forwardRef(function TabsItem({
selected,
...props
}, ref) {
return <ItemContainer
return <Box
is='button'
componentClassName='rcx-tabs__item'
aria-selected={selected ? 'true' : 'false'}
mod-selected={selected}
ref={ref}
Expand All @@ -33,4 +31,8 @@ export const TabsItem = forwardRef(function TabsItem({
/>;
});

TabsItem.propTypes = {
selected: PropTypes.bool,
};

Tabs.Item = TabsItem;
4 changes: 1 addition & 3 deletions packages/fuselage/src/components/Tabs/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@
color: $tabs-disabled-color;
}

&.focus,
&:focus {

@include on-focus-visible {
padding-inline: $spaces-x16;

border-color: $tabs-focus-border-color;
Expand Down
16 changes: 16 additions & 0 deletions packages/fuselage/src/styles/mixins/states.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
}
}

@mixin on-focus-visible {
&:focus-visible {
@content;
}

@at-root .js-focus-visible &:focus.focus-visible, .js-focus-visible &.focus.focus-visible {
@content;
}

@at-root html:not(.js-focus-visible) & {
@include on-focus {
@content;
}
}
}

@mixin on-disabled {
*:disabled &,
&:disabled,
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage/src/styles/primitives/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

appearance: none;

@include on-focus {
@include on-focus-visible {
border-color: $focus-border-color;
background-color: $focus-background-color;
@include use-focus-shadow($focus-shadow-color);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8432,6 +8432,11 @@ focus-lock@^0.6.3:
resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.6.6.tgz#98119a755a38cfdbeda0280eaa77e307eee850c7"
integrity sha512-Dx69IXGCq1qsUExWuG+5wkiMqVM/zGx/reXSJSLogECwp3x6KeNQZ+NAetgxEFpnC41rD8U3+jRCW68+LNzdtw==

focus-visible@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/focus-visible/-/focus-visible-5.0.2.tgz#4fae9cf40458b73c10701c9774c462e3ccd53caf"
integrity sha512-zT2fj/bmOgEBjqGbURGlowTmCwsIs3bRDMr/sFZz8Ly7VkEiwuCn9swNTL3pPuf8Oua2de7CLuKdnuNajWdDsQ==

for-in@^0.1.3:
version "0.1.8"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"
Expand Down

0 comments on commit 0801f28

Please sign in to comment.