Skip to content

Commit

Permalink
refactor(@air/zephyr): upgrade radix packages
Browse files Browse the repository at this point in the history
  • Loading branch information
andyhqtran committed Nov 3, 2022
1 parent f15b9c3 commit 66d4f6d
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 488 deletions.
9 changes: 6 additions & 3 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ThemeProvider } from 'styled-components';

import { theme } from '../packages/zephyr/src/theme';
import { TooltipProvider } from '../packages/zephyr/src/Tooltip';

export const parameters = {
actions: { argTypesRegex: '^on.*' },
Expand All @@ -12,9 +13,11 @@ export const parameters = {
};

const ThemeWrapper = (Story) => (
<ThemeProvider theme={theme}>
<Story />
</ThemeProvider>
<TooltipProvider>
<ThemeProvider theme={theme}>
<Story />
</ThemeProvider>
</TooltipProvider>
);

export const decorators = [ThemeWrapper];
13 changes: 7 additions & 6 deletions packages/zephyr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"url": "https://github.com/AirLabsTeam/web-core/issues"
},
"scripts": {
"start": "tsdx watch --verbose --noClean --tsconfig tsconfig.build.json",
"build": "tsdx build --tsconfig tsconfig.build.json",
"start": "tsdx watch --verbose --noClean --tsconfig tsconfig.json",
"build": "tsdx build --tsconfig tsconfig.json",
"test": "tsdx test --passWithNoTests",
"lint": "tsdx lint"
},
Expand All @@ -58,16 +58,17 @@
"yup": "^0.32.9"
},
"dependencies": {
"@radix-ui/react-dropdown-menu": "^0.1.4",
"@radix-ui/react-slot": "^0.0.4",
"@radix-ui/react-tooltip": "^0.1.6",
"@radix-ui/popper": "^0.1.0",
"@radix-ui/react-dropdown-menu": "^2.0.1",
"@radix-ui/react-slot": "^1.0.1",
"@radix-ui/react-tooltip": "^1.0.2",
"@radix-ui/react-visually-hidden": "^1.0.1",
"@reach/alert-dialog": "^0.11.2",
"@reach/auto-id": "^0.11.2",
"@reach/dialog": "^0.11.2",
"@reach/menu-button": "^0.11.2",
"@reach/rect": "^0.11.2",
"@reach/utils": "0.11.2",
"@reach/visually-hidden": "^0.11.1",
"classnames": "^2.2.6",
"react-contexify": "^5.0.0",
"react-use": "^15.3.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Close as CloseIcon } from '@air/icons';
import VisuallyHidden from '@reach/visually-hidden';
import { VisuallyHidden } from '../../VisuallyHidden';

import { Box } from '../../Box';
import { IconButton } from '../../IconButton';
Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { transitions } from 'polished';
import { forwardRefWithAs, PropsWithAs } from '@reach/utils';
import { variant as styledSystemVariant } from 'styled-system';
import { useReducedMotion } from 'framer-motion';
import VisuallyHidden from '@reach/visually-hidden';
import classNames from 'classnames';
import { Ref } from 'react';
import styled, { keyframes, useTheme } from 'styled-components';
import { VisuallyHidden } from './VisuallyHidden';
import { Box, BoxStylingProps } from './Box';
import { ButtonVariantName } from './theme/variants/button';
import { LeftRight, SVGComponent } from './shared';
Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/Forms/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Check } from '@air/icons';
import { useId } from '@reach/auto-id';
import VisuallyHidden from '@reach/visually-hidden';

import { VisuallyHidden } from '../VisuallyHidden';
import { SVGComponent } from '../shared';
import { Box, BoxProps } from '../Box';
import { Label } from './Label';
Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/Forms/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ReactNode, ChangeEvent, MutableRefObject, useMemo } from 'react';
import { useField } from 'formik';
import VisuallyHidden from '@reach/visually-hidden';
import { variant as styledSystemVariant } from 'styled-system';
import { useTheme } from 'styled-components';
import { LeftRight } from '../shared';
import { Box, BoxStylingProps } from '../Box';
import { Text } from '../Text';
import { FieldVariantName, TXProp } from '../theme';
import { VisuallyHidden } from '../VisuallyHidden';
import { Label } from './Label';
import { Error } from './Error';

Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/Forms/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VisuallyHidden from '@reach/visually-hidden';
import { VisuallyHidden } from '../VisuallyHidden';
import { BoxProps } from '../Box';
import { Text } from '../Text';
import { TextVariantName } from '../theme/variants/text';
Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/Forms/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useId } from '@reach/auto-id';
import VisuallyHidden from '@reach/visually-hidden';

import { TXProp } from '../../theme';
import { Box, BoxProps } from '../../Box';
import { Label } from '../Label';
import { VisuallyHidden } from '../../VisuallyHidden';

export interface ToggleProps {
['data-testid']?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { forwardRefWithAs } from '@reach/utils';
import VisuallyHidden from '@reach/visually-hidden';
import { variant as styledSystemVariant } from 'styled-system';
import { Ref } from 'react';
import { useTheme } from 'styled-components';
import { Tooltip, TooltipProps } from '../src/Tooltip';
import { VisuallyHidden } from './VisuallyHidden';
import { Box } from './Box';
import { Button, ButtonProps, NonSemanticButtonProps } from './Button';
import { SVGComponent } from './shared';
Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/Modals/AnnouncementModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { forwardRef, useRef, MutableRefObject } from 'react';
import VisuallyHidden from '@reach/visually-hidden';
import { isString } from 'lodash';
import { Box, BoxProps } from '../Box';
import { Button, ButtonProps } from '../Button';
import { Text } from '../Text';
import { VisuallyHidden } from '../VisuallyHidden';
import { Modal, ModalProps } from './Modal';

export const ANNOUNCEMENT_MODAL_CTA = 'ANNOUNCEMENT_MODAL_CTA';
Expand Down
2 changes: 1 addition & 1 deletion packages/zephyr/src/Modals/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ModalProps
/**
* This will be used to go into further detail regarding the modal. Optional, but required if leveraging an
* alert modal. If you want the description invisible, please render the node within
* [@reach/visually-hidden](https://reach.tech/visually-hidden).
* [@radix-ui/react-visually-hidden](https://reach.tech/visually-hidden).
*
* - Example: `<VisuallyHidden>This action is permanent, are you sure?</VisuallyHidden>`
*
Expand Down
18 changes: 9 additions & 9 deletions packages/zephyr/src/RadixMenu/components/RadixMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode, memo, useCallback, useMemo } from 'react';
import { rgba } from 'polished';
import { Item, Root, Content, TriggerItem } from '@radix-ui/react-dropdown-menu';
import * as RadixDropdownMenu from '@radix-ui/react-dropdown-menu';
import { ChevronRight } from '@air/icons';
import { useTheme } from 'styled-components';

Expand Down Expand Up @@ -259,13 +259,13 @@ export const RadixMenuItem = memo(
if (!!subOptions && subOptions.length) {
return (
<Box tx={menuItemStyle}>
<Root>
<RadixDropdownMenu.Sub>
{hasDividerTop && <RadixMenuItemDivider isTop />}
<TriggerItem className="radix-menu-item" disabled={disabled}>
<RadixDropdownMenu.SubTrigger className="radix-menu-item" disabled={disabled}>
{menuItemContent}
</TriggerItem>
</RadixDropdownMenu.SubTrigger>
{hasDividerBottom && <RadixMenuItemDivider />}
<Content>
<RadixDropdownMenu.SubContent>
<Box
tx={{
display: 'flex',
Expand Down Expand Up @@ -295,24 +295,24 @@ export const RadixMenuItem = memo(
/>
))}
</Box>
</Content>
</Root>
</RadixDropdownMenu.SubContent>
</RadixDropdownMenu.Sub>
</Box>
);
}

return (
<Box tx={menuItemStyle} {...renderProps}>
{hasDividerTop && <RadixMenuItemDivider variant={variant} isTop />}
<Item
<RadixDropdownMenu.Item
data-testid={testId ?? id}
id={id}
className="radix-menu-item"
disabled={disabled}
onSelect={onClick ?? onSelect}
>
{menuItemContent}
</Item>
</RadixDropdownMenu.Item>
{hasDividerBottom && <RadixMenuItemDivider variant={variant} />}
</Box>
);
Expand Down
102 changes: 52 additions & 50 deletions packages/zephyr/src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const Tooltip = ({
avoidCollisions,
baseZIndex = 10,
children,
collisionTolerance,
label,
manualControlProps,
side,
Expand All @@ -155,59 +154,62 @@ export const Tooltip = ({
* */}
<RadixTooltip.Trigger asChild>{children}</RadixTooltip.Trigger>

<RadixTooltip.Content
side={side}
sideOffset={sideOffset}
align={align}
alignOffset={alignOffset}
collisionTolerance={collisionTolerance}
avoidCollisions={avoidCollisions}
>
<Box
aria-label={ariaLabel}
data-testid={testID}
tx={{
bg: 'black',
color: 'white',
px: 10,
py: 5,
minHeight: 36,
borderColor: 'transparent',
borderWidth: 2,
borderStyle: 'solid',
borderRadius: 4,
zIndex: baseZIndex + 1,
...(containerStyles as any),
}}
<RadixTooltip.Portal>
<RadixTooltip.Content
side={side}
sideOffset={sideOffset}
align={align}
alignOffset={alignOffset}
avoidCollisions={avoidCollisions}
>
<Text
variant="text-ui-14"
<Box
aria-label={ariaLabel}
data-testid={testID}
tx={{
color: 'currentColor',
fontWeight: 'medium',
...(textContentStyles as any),
bg: 'black',
color: 'white',
px: 10,
py: 5,
minHeight: 36,
borderColor: 'transparent',
borderWidth: 2,
borderStyle: 'solid',
borderRadius: 4,
zIndex: baseZIndex + 1,
...(containerStyles as any),
}}
>
{label}
</Text>

{withArrow && (
<RadixTooltip.Arrow width={10} height={7} offset={arrowOffset}>
<Box
tx={{
zIndex: baseZIndex + 1,
strokeLinejoin: 'round',
strokeLinecap: 'round',
stroke: 'black',
strokeWidth: 1,
...triangleOffsetMapping['base'][side],
...(arrowStyles as any),
}}
/>
</RadixTooltip.Arrow>
)}
</Box>
</RadixTooltip.Content>
<Text
variant="text-ui-14"
tx={{
color: 'currentColor',
fontWeight: 'medium',
...(textContentStyles as any),
}}
>
{label}
</Text>

{withArrow && (
<RadixTooltip.Arrow width={10} height={7} offset={arrowOffset}>
<Box
tx={{
zIndex: baseZIndex + 1,
strokeLinejoin: 'round',
strokeLinecap: 'round',
stroke: 'black',
strokeWidth: 1,
...triangleOffsetMapping['base'][side],
...(arrowStyles as any),
}}
/>
</RadixTooltip.Arrow>
)}
</Box>
</RadixTooltip.Content>
</RadixTooltip.Portal>
</RadixTooltip.Root>
);
};

export const TooltipProvider = RadixTooltip.Provider;
3 changes: 3 additions & 0 deletions packages/zephyr/src/VisuallyHidden.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as RadixVisuallyHidden from '@radix-ui/react-visually-hidden';

export const VisuallyHidden = RadixVisuallyHidden.Root;
2 changes: 1 addition & 1 deletion packages/zephyr/stories/forms/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Formik, Form } from 'formik';
import { number, object, string } from 'yup';
import { StoryFnReactReturnType } from '@storybook/react/dist/ts3.9/client/preview/types';
import { Caution, Search, EyeClosed, Eye } from '@air/icons';
import VisuallyHidden from '@reach/visually-hidden';
import { capitalize, noop } from 'lodash';
import { Box } from '../../src/Box';
import { Button } from '../../src/Button';
import { Text } from '../../src/Text';
import { Input, InputProps } from '../../src/Forms/Input';
import { FieldVariantName, field } from '../../src/theme/variants/field';
import { VisuallyHidden } from '../../src/VisuallyHidden';

const variants = Object.keys(field) as FieldVariantName[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ withSubOptions.args = {
leftAdornment: <Box as={AddMemberIcon} tx={{ display: 'block', width: 16 }} />,
label: 'Add members',
description: 'Invite members or guests to collaborate on this board',
hasDividerBottom: true,
onSelect: () => {},
},
],
Expand Down
File renamed without changes.
Loading

1 comment on commit 66d4f6d

@vercel
Copy link

@vercel vercel bot commented on 66d4f6d Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

air-core – ./

air-core-air-inc.vercel.app
air-zephyr.vercel.app
design.air.inc
air-core-git-main-air-inc.vercel.app

Please sign in to comment.