Skip to content

Commit

Permalink
fix: Errors with type imports and exports in Storybook (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmar authored Nov 24, 2022
1 parent ce478a0 commit 1c0eb07
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 91 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
module.exports = {
parserOptions: {
project: './tsconfig.json',
},
extends: [
'@pluralsh/eslint-config-typescript',
'plugin:storybook/recommended',
],
globals: {
JSX: true,
},
rules: {
'@typescript-eslint/consistent-type-exports': 'error',
},
}
17 changes: 12 additions & 5 deletions src/components/AppIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,29 @@ type AppIconProps = DivProps & {
}

const propTypes = {
size: PropTypes.oneOf(['xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge']),
size: PropTypes.oneOf([
'xxsmall',
'xsmall',
'small',
'medium',
'large',
'xlarge',
]),
spacing: PropTypes.oneOf(['none', 'padding']),
hue: PropTypes.oneOf(['default', 'lighter', 'lightest']),
clickable: PropTypes.bool,
url: PropTypes.string,
alt: PropTypes.string,
}

const parentFillLevelToHue:Record<FillLevel, Hue> = {
const parentFillLevelToHue: Record<FillLevel, Hue> = {
0: 'default',
1: 'lighter',
2: 'lightest',
3: 'lightest',
}

const sizeToWidth:Record<Size, number> = {
const sizeToWidth: Record<Size, number> = {
xxsmall: 32,
xsmall: 40,
small: 64,
Expand All @@ -47,7 +54,7 @@ const sizeToWidth:Record<Size, number> = {
xlarge: 160,
}

const sizeToIconWidth:Record<Size, number> = {
const sizeToIconWidth: Record<Size, number> = {
xxsmall: 16,
xsmall: 24,
small: 48,
Expand Down Expand Up @@ -164,4 +171,4 @@ const AppIcon = forwardRef(AppIconRef)
AppIcon.propTypes = propTypes

export default AppIcon
export { AppIconProps }
export type { AppIconProps }
2 changes: 1 addition & 1 deletion src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ ref) => {
})

export default Card
export { CardProps, CornerSize as CardSize, CardHue }
export type { CardProps, CornerSize as CardSize, CardHue }
69 changes: 48 additions & 21 deletions src/components/Checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const Checklist = styled(ChecklistUnstyled)(({ theme }) => ({
type ChecklistProps = ComponentPropsWithRef<'div'> & {
label: string
stateProps: ChecklistStateProps
footerChildren: ReactElement<ChecklistFooterProps> | ReactElement<ChecklistFooterProps>[]
footerChildren:
| ReactElement<ChecklistFooterProps>
| ReactElement<ChecklistFooterProps>[]
completeChildren: ReactElement
children: ReactElement<ChecklistItemProps>[]
}
Expand All @@ -85,9 +87,9 @@ type ChecklistStateProps = {
onSelectionChange?: Dispatch<number>
onFocusChange?: Dispatch<number>
onOpenChange?: Dispatch<boolean>
selectedKey?: number,
focusedKey?: number,
completedKey?: number,
selectedKey?: number
focusedKey?: number
completedKey?: number
isOpen?: boolean
isDismissed?: boolean
}
Expand All @@ -101,7 +103,14 @@ function ChecklistUnstyled({
...props
}: ChecklistProps): JSX.Element {
const {
isOpen = true, isDismissed, selectedKey, focusedKey, completedKey, onSelectionChange, onFocusChange, onOpenChange,
isOpen = true,
isDismissed,
selectedKey,
focusedKey,
completedKey,
onSelectionChange,
onFocusChange,
onOpenChange,
} = stateProps
const [finished, setFinished] = useState(false)

Expand All @@ -110,7 +119,8 @@ function ChecklistUnstyled({
const finishedContainerRef = useRef<HTMLDivElement>(null)

const [itemContainerHeight, setItemContainerHeight] = useState<number>(-1)
const [finishedContainerHeight, setFinishedContainerHeight] = useState<number>(-1)
const [finishedContainerHeight, setFinishedContainerHeight]
= useState<number>(-1)

const onSelectionChangeWrapper = useCallback((idx: number) => (idx < children.length && idx > -1 ? onSelectionChange(idx) : undefined),
[children, onSelectionChange])
Expand All @@ -127,9 +137,18 @@ function ChecklistUnstyled({
completed={completedKey >= index}
onSelectionChange={onSelectionChangeWrapper}
onFocusChange={onFocusChangeWrapper}
>{child}
>
{child}
</ChecklistItemInner>
)), [children, selectedKey, focusedKey, completedKey, onSelectionChangeWrapper, onFocusChangeWrapper])
)),
[
children,
selectedKey,
focusedKey,
completedKey,
onSelectionChangeWrapper,
onFocusChangeWrapper,
])

useEffect(() => {
setFinished(completedKey === children.length - 1)
Expand All @@ -142,12 +161,21 @@ function ChecklistUnstyled({
})

useEffect(() => {
const maxItemContainerHeight = Math.max(itemContainerHeight, itemsContainerRef.current.getBoundingClientRect().height)
const maxFinishedContainerHeight = Math.max(finishedContainerHeight, finishedContainerRef.current.getBoundingClientRect().height)
const maxItemContainerHeight = Math.max(itemContainerHeight,
itemsContainerRef.current.getBoundingClientRect().height)
const maxFinishedContainerHeight = Math.max(finishedContainerHeight,
finishedContainerRef.current.getBoundingClientRect().height)

setItemContainerHeight(maxItemContainerHeight)
setFinishedContainerHeight(maxFinishedContainerHeight)
}, [itemsContainerRef, finishedContainerRef, setItemContainerHeight, setFinishedContainerHeight, itemContainerHeight, finishedContainerHeight])
}, [
itemsContainerRef,
finishedContainerRef,
setItemContainerHeight,
setFinishedContainerHeight,
itemContainerHeight,
finishedContainerHeight,
])

return (
<AnimateHeight
Expand All @@ -164,25 +192,23 @@ function ChecklistUnstyled({
onClick={() => onOpenChange(!isOpen)}
>
<div>{label}</div>
<DropdownArrowIcon
className={isOpen ? 'arrowUp' : 'arrowDown'}
/>
<DropdownArrowIcon className={isOpen ? 'arrowUp' : 'arrowDown'} />
</div>
<AnimateHeight
height={isFirstRender.current || isOpen ? 'auto' : 0}
duration={heightAnimationDuration}
>
<div
className="content"
>
{checklistItemInnerWrapper}
</div>
<div className="content">{checklistItemInnerWrapper}</div>
<ChecklistFooter>{footerChildren}</ChecklistFooter>
</AnimateHeight>
</div>
<div
className={finished ? 'finishContainer grow' : 'finishContainer shrink'}
style={isFirstRender.current || finished ? { maxHeight: finishedContainerHeight } : { maxHeight: 0, padding: 0 }}
style={
isFirstRender.current || finished
? { maxHeight: finishedContainerHeight }
: { maxHeight: 0, padding: 0 }
}
ref={finishedContainerRef}
>
{completeChildren}
Expand All @@ -191,4 +217,5 @@ function ChecklistUnstyled({
)
}

export { Checklist, ChecklistStateProps, ChecklistProps }
export type { ChecklistStateProps, ChecklistProps }
export { Checklist }
5 changes: 3 additions & 2 deletions src/components/ChecklistFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function ChecklistFooterUnstyled({
children,
...props
}: ChecklistFooterProps): JSX.Element {
return (<div {...props}>{children}</div>)
return <div {...props}>{children}</div>
}

export { ChecklistFooter, ChecklistFooterProps }
export type { ChecklistFooterProps }
export { ChecklistFooter }
14 changes: 6 additions & 8 deletions src/components/ChecklistItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const ChecklistItemInner = styled(ChecklistItemInnerUnstyled)(({ theme, complete
display: 'flex',
gap: 12,
alignItems: 'center',
color: selected ? theme.colors['action-link-active'] : theme.colors['action-link-inactive'],
color: selected
? theme.colors['action-link-active']
: theme.colors['action-link-inactive'],
cursor: 'pointer',

':hover': {
Expand Down Expand Up @@ -152,12 +154,7 @@ function ChecklistItem({
children,
...props
}: ChecklistItemProps): JSX.Element {
return (
<div
{...props}
>{children}
</div>
)
return <div {...props}>{children}</div>
}

enum KeyboardKey {
Expand Down Expand Up @@ -251,4 +248,5 @@ function ChecklistItemInnerUnstyled({
)
}

export { ChecklistItem, ChecklistItemInner, ChecklistItemProps }
export type { ChecklistItemProps }
export { ChecklistItem, ChecklistItemInner }
2 changes: 1 addition & 1 deletion src/components/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,4 @@ const Code = styled(forwardRef(CodeRef))(_ => ({
Code.propTypes = propTypes

export default Code
export { CodeProps }
export type { CodeProps }
10 changes: 6 additions & 4 deletions src/components/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ function ComboBox({
},
[isOpen, onOpenChange])

const setIsOpen = useCallback((isOpen:boolean) => {
const setIsOpen = useCallback((isOpen: boolean) => {
wrappedOnOpenChange(isOpen, 'manual')
}, [wrappedOnOpenChange])
},
[wrappedOnOpenChange])

const wrappedOnSelectionChange: typeof onSelectionChange = useCallback((newKey, ...args) => {
if (onSelectionChange) {
Expand All @@ -273,7 +274,7 @@ function ComboBox({
[onSelectionChange, setIsOpen])

const wrappedOnFocusChange: typeof onFocusChange = useCallback((isFocused, ...args) => {
// Enforce open on focus
// Enforce open on focus
if (isFocused && !isOpen) {
setIsOpen(true)
}
Expand Down Expand Up @@ -391,4 +392,5 @@ function ComboBox({
)
}

export { ComboBox, ComboBoxProps }
export type { ComboBoxProps }
export { ComboBox }
2 changes: 1 addition & 1 deletion src/components/IconFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ ref) => {
})

export default IconFrame
export { IconFrameProps }
export type { IconFrameProps }
13 changes: 4 additions & 9 deletions src/components/ListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ListBoxProps = Omit<
footer?: ReactElement
}

const CARD_FILL_LEVEL:FillLevel = 2
const CARD_FILL_LEVEL: FillLevel = 2

const ListBoxCard = styled(Card).attrs(() => ({
cornerSize: 'medium',
Expand Down Expand Up @@ -84,7 +84,7 @@ function useItemWrappedChildren(children: ReactElement | ReactElement[],
return useMemo(() => {
// Children.map() prefixes the key props in an undocumented and possibly
// unstable way, so using Children.forEach() to maintain original key values
const wrapped: (JSX.Element)[] = []
const wrapped: JSX.Element[] = []

if (header) {
wrapped.push(<Item key={HEADER_KEY}>{header}</Item>)
Expand Down Expand Up @@ -245,10 +245,5 @@ function Option({ item, state }: any) {
return cloneElement(item.rendered, mergedProps)
}

export {
ListBox,
ListBoxProps,
ListBoxUnmanaged,
ListBoxUnmanagedProps,
useItemWrappedChildren,
}
export type { ListBoxProps, ListBoxUnmanagedProps }
export { ListBox, ListBoxUnmanaged, useItemWrappedChildren }
8 changes: 5 additions & 3 deletions src/components/ListBoxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,14 @@ const ListBoxFooterPlus = forwardRef<HTMLDivElement, ListBoxFooterProps>(({ left
</ListBoxFooterPlusInner>
))

export type {
ListBoxItemBaseProps,
ListBoxFooterProps,
ListBoxFooterProps as ListBoxFooterPlusProps,
}
export {
ListBoxItem,
ListBoxItemBaseProps,
ChipList as ListBoxItemChipList,
ListBoxFooter,
ListBoxFooterProps,
ListBoxFooterPlus,
ListBoxFooterProps as ListBoxFooterPlusProps,
}
2 changes: 1 addition & 1 deletion src/components/PageCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ ref) => (
))

export default PageCard
export { PageCardProps }
export type { PageCardProps }
3 changes: 2 additions & 1 deletion src/components/PopoverListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ function PopoverListBox({
)
}

export { PopoverListBox, PopoverListBoxProps }
export type { PopoverListBoxProps }
export { PopoverListBox }
3 changes: 2 additions & 1 deletion src/components/ReactAriaPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ const PopoverStyled = styled.div<{ $isOpen: boolean }>(({ $isOpen: isOpen }) =>
...(!isOpen ? { pointerEvents: 'none' } : {}),
}))

export { Popover, PopoverProps }
export type { PopoverProps }
export { Popover }
9 changes: 5 additions & 4 deletions src/components/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { useTheme } from 'styled-components'

import { TabBaseProps } from './TabList'

type TabProps = DivProps & TabBaseProps & {
startIcon?: ReactNode
}
type TabProps = DivProps &
TabBaseProps & {
startIcon?: ReactNode
}

function TabRef({
startIcon,
Expand Down Expand Up @@ -83,4 +84,4 @@ ref: Ref<any>) {
const Tab = forwardRef(TabRef)

export default Tab
export { TabProps }
export type { TabProps }
5 changes: 2 additions & 3 deletions src/components/TabList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,5 @@ function TabRenderer({
)
}

export {
TabList, TabListProps, TabListStateProps, TabBaseProps,
}
export type { TabListProps, TabListStateProps, TabBaseProps }
export { TabList }
2 changes: 1 addition & 1 deletion src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ function Tooltip({
}

export default Tooltip
export { TooltipProps }
export type { TooltipProps }
Loading

0 comments on commit 1c0eb07

Please sign in to comment.