Skip to content

Commit

Permalink
feat(onboarding-ui): Common components (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored Jun 30, 2021
1 parent 1b6b70c commit d7511ab
Show file tree
Hide file tree
Showing 53 changed files with 649 additions and 64 deletions.
11 changes: 9 additions & 2 deletions packages/css-in-js/src/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ const elementId = 'rcx-styles';
let element: HTMLStyleElement;
const getStyleTag = (): HTMLStyleElement => {
if (!element) {
element = (document.getElementById(elementId) ||
document.createElement('style')) as HTMLStyleElement;
const el = document.getElementById(elementId) as HTMLStyleElement;
if (el) {
element = el;
return element;
}
}

if (!element) {
element = document.createElement('style');
element.id = elementId;
element.appendChild(document.createTextNode(''));
if (document.head) {
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage-hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './useAutoFocus';
export * from './useBreakpoints';
export * from './useClipboard';
export * from './useDarkMode';
export * from './useDebouncedCallback';
export * from './useDebouncedReducer';
export * from './useDebouncedState';
Expand Down
11 changes: 11 additions & 0 deletions packages/fuselage-hooks/src/useDarkMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { usePrefersColorScheme } from './usePrefersColorScheme';

export const useDarkMode = (forced?: boolean): boolean => {
const systemDarkMode = usePrefersColorScheme('dark');

if (forced !== undefined) {
return forced;
}

return systemDarkMode;
};
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ReactElement, ReactNode } from 'react';

type AnimatedVisibilityProps = {
children: ReactNode;
visibility?: 'hidden' | 'visible' | 'hiding' | 'unhiding';
};

const AnimatedVisibility: {
(props: AnimatedVisibilityProps): ReactElement;
HIDDEN: 'hidden';
VISIBLE: 'visible';
HIDING: 'hiding';
UNHIDING: 'unhiding';
};

export = AnimatedVisibility;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './AnimatedVisibility';
1 change: 1 addition & 0 deletions packages/fuselage/src/components/Box/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ type BoxProps = PropsWithChildren<{

export const Box: ForwardRefExoticComponent<BoxProps>;

export { default as AnimatedVisibility } from './AnimatedVisibility';
export { default as Position, PositionAnimated } from './Position';
export { default as Scrollable } from './Scrollable';
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Meta, Story } from '@storybook/react';
import React from 'react';

import { Icon, PasswordInput } from '../..';
Expand All @@ -8,25 +7,25 @@ export default {
title: 'Forms/Inputs/PasswordInput',
component: PasswordInput,
parameters: { jest: ['PasswordInput.spec.tsx'] },
} as Meta;
};

export const Default: Story = () => <PasswordInput />;
export const Default = () => <PasswordInput />;

export const WithValue: Story = () => <PasswordInput defaultValue='password' />;
export const WithValue = () => <PasswordInput defaultValue='password' />;

export const WithIconAddon: Story = () => (
export const WithIconAddon = () => (
<PasswordInput addon={<Icon name='send' size={20} />} />
);

export const Invalid: Story = () => <PasswordInput error='Error' />;
export const Invalid = () => <PasswordInput error='Error' />;

export const Disabled: Story = () => <PasswordInput disabled />;
export const Disabled = () => <PasswordInput disabled />;

export const WithPlaceholder: Story = () => (
export const WithPlaceholder = () => (
<PasswordInput placeholder='Placeholder' />
);

export const States: Story = () => (
export const States = () => (
<PropsVariation
component={PasswordInput}
common={{ onChange: () => undefined }}
Expand Down
39 changes: 22 additions & 17 deletions packages/fuselage/src/components/Tooltip/Tooltip.styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@use '../../styles/colors.scss';
@use '../../styles/lengths.scss';
@use '../../styles/typography.scss';
@use '../../styles/functions.scss';

Expand All @@ -17,35 +16,37 @@ $tooltip-text-color: functions.theme('tooltip-text-color', colors.surface());

content: ' ';

border-width: lengths.border-width(4) + lengths.border-width(1);
border-width: 4px;
border-color: transparent transparent $tooltip-background-color
$tooltip-background-color;
border-radius: lengths.border-radius(none) lengths.border-radius(none)
lengths.border-radius(none) (lengths.border-radius(2) + to-rem(1));
border-radius: 0 0 0 (2px);

block-size: 0;
inline-size: 0;

@if $direction == 'bottom' {
inset-block-start: lengths.inset(-4);
inset-block-start: -4px;

transform: rotate(135deg);
}
@if $direction == 'top' {
inset-block-end: lengths.inset(-4);
inset-block-end: -4px;

transform: rotate(-45deg);
}
@if $direction == 'right' {
inset-block-start: 50%;
inset-inline-start: lengths.inset(-4);
inset-inline-start: -4px;

margin-block-start: lengths.margin(-4);
margin-block-start: -4px;

transform: rotate(45deg);
}
@if $direction == 'left' {
inset-block-start: 50%;
inset-inline-end: lengths.inset(-4);
inset-inline-end: -4px;

margin-block-start: lengths.margin(-4);
margin-block-start: -4px;

transform: rotate(-135deg);
}
Expand All @@ -57,15 +58,19 @@ $tooltip-text-color: functions.theme('tooltip-text-color', colors.surface());

display: inline-block;

max-width: lengths.size(240);
max-width: 240px;

padding: 8px 12px;

padding: lengths.padding(8) lengths.padding(12);
user-select: none;

word-break: break-word;

pointer-events: none;

color: $tooltip-text-color;

border-radius: lengths.border-radius(4);
border-radius: 4px;

background-color: $tooltip-background-color;

Expand All @@ -92,22 +97,22 @@ $tooltip-text-color: functions.theme('tooltip-text-color', colors.surface());
&::after {
inset-inline-start: 50%;

margin-inline-start: lengths.margin(-4);
margin-inline-start: -4px;
}
}

&-start {
&::after {
inset-inline-start: lengths.inset(8);
inset-inline-start: 8px;

margin: lengths.margin(none);
margin: 0;
}
}

&-end {
&::after {
inset-inline-start: initial;
inset-inline-end: lengths.inset(8);
inset-inline-end: 8px;

margin: 0;
}
Expand Down
22 changes: 13 additions & 9 deletions packages/fuselage/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import { useStyleSheet } from '../../hooks/useStyleSheet';
import { Box } from '../Box';
import tooltipStyleSheet from './Tooltip.styles.scss';

const parsePlacement = (placement: string | null | undefined) => {
const [direction, position] = placement
? placement.split('-')
: [false, false];

if (direction === 'right' || direction === 'left') {
return [direction, false];
}

return [direction, position];
};

type TooltipProps = ComponentProps<typeof Box> & {
placement?:
| 'top-start'
Expand All @@ -12,12 +24,6 @@ type TooltipProps = ComponentProps<typeof Box> & {
| 'bottom-start'
| 'bottom-middle'
| 'bottom-end'
| 'left-start'
| 'left-middle'
| 'left-end'
| 'right-start'
| 'right-middle'
| 'right-end'
| 'top'
| 'left'
| 'bottom'
Expand All @@ -32,9 +38,7 @@ const Tooltip = forwardRef(function Tooltip(
useStyleSheet();
useStyleSheet(tooltipStyleSheet);

const [direction, position] = placement
? placement.split('-')
: [false, false];
const [direction, position] = parsePlacement(placement);

return (
<Box
Expand Down
8 changes: 8 additions & 0 deletions packages/fuselage/tsconfig-bundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
},
"include": ["./src"],
"exclude": ["./**/*.stories.tsx"]
}
7 changes: 6 additions & 1 deletion packages/fuselage/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ module.exports = (env, { mode = 'production' }) => ({
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: 'ts-loader',
use: {
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, './tsconfig-bundle.json'),
},
},
},
{
test: /\.scss$/,
Expand Down
5 changes: 4 additions & 1 deletion packages/onboarding-ui/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
extends: '@rocket.chat/eslint-config-alt/typescript',
extends: '@rocket.chat/eslint-config-alt/react',
env: {
jest: true,
},
rules: {
'react/react-in-jsx-scope': 'off',
},
};
5 changes: 5 additions & 0 deletions packages/onboarding-ui/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"src/**/*.{js,ts,tsx}": [
"yarn run eslint --fix --"
]
}
2 changes: 2 additions & 0 deletions packages/onboarding-ui/.loki/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
current
difference
Binary file not shown.
Binary file not shown.
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.
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.
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.
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.
20 changes: 15 additions & 5 deletions packages/onboarding-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"devDependencies": {
"@rocket.chat/eslint-config-alt": "^0.27.0",
"@rocket.chat/fuselage-polyfills": "^0.27.0",
"@rocket.chat/fuselage-tokens": "^0.27.0",
"@rocket.chat/prettier-config": "^0.27.0",
"@storybook/addon-essentials": "^6.3.1",
Expand Down Expand Up @@ -75,25 +76,34 @@
"dependencies": {
"@rocket.chat/fuselage": "^0.27.0",
"@rocket.chat/fuselage-hooks": "^0.27.0",
"@rocket.chat/fuselage-polyfills": "^0.27.0",
"@rocket.chat/icons": "^0.27.0",
"@rocket.chat/styled": "workspace:packages/styled",
"tslib": "^2.3.0"
},
"peerDependencies": {
"@rocket.chat/fuselage-polyfills": "^0.27.0",
"react": "17.0.2",
"react-dom": "17.0.2"
},
"loki": {
"configurations": {
"chrome.laptop": {
"desktop": {
"target": "chrome.docker",
"width": 1440,
"height": 896,
"deviceScaleFactor": 1,
"mobile": false,
"fitWindow": false
},
"tablet": {
"target": "chrome.docker",
"width": 1366,
"height": 768,
"width": 768,
"height": 970,
"deviceScaleFactor": 1,
"mobile": false,
"fitWindow": false
},
"chrome.iphone7": {
"mobile": {
"target": "chrome.docker",
"preset": "iPhone 7"
}
Expand Down
10 changes: 0 additions & 10 deletions packages/onboarding-ui/src/MyComponent.stories.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions packages/onboarding-ui/src/MyComponent.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions packages/onboarding-ui/src/common/.gitignore

This file was deleted.

9 changes: 9 additions & 0 deletions packages/onboarding-ui/src/common/BackgroundLayer.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ReactDOM from 'react-dom';

import BackgroundLayer from './BackgroundLayer';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<BackgroundLayer />, div);
ReactDOM.unmountComponentAtNode(div);
});
Loading

0 comments on commit d7511ab

Please sign in to comment.