This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: convert components to ts (#150)
* Convert to TS * compile jsx * snaps and fixes * add defaults back in * remove js file * fix breakpoints * use es5 because of EMR webpack uglify complaint * es2015 * Revert "es2015" This reverts commit fa19ec1. * Revert "use es5 because of EMR webpack uglify complaint" This reverts commit 85e6e3a. * add tslib * use interface instead of type * bump version
- Loading branch information
1 parent
39efe8b
commit 96849ec
Showing
161 changed files
with
1,450 additions
and
1,203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ lib | |
coverage | ||
.yalc | ||
yalc.lock | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'react-animations' {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,8 @@ | ||
// import original module declarations | ||
import 'styled-components'; | ||
import { ThemeColors, ThemeBreakpoints, ThemeTypography, ThemeSizes, ThemeVariants } from 'src/types'; | ||
import { Theme } from 'types'; | ||
|
||
// and extend them! | ||
declare module 'styled-components' { | ||
export interface DefaultTheme extends Theme { | ||
classPrefix: string; | ||
space: number[]; | ||
gridWidth: number; | ||
gridGutter: number; | ||
gridColumns: number; | ||
radii: number[]; | ||
radius: number; | ||
shadow: { | ||
soft: string; | ||
hard: string; | ||
}; | ||
colors: ThemeColors; | ||
breakpoints: ThemeBreakpoints; | ||
typography: ThemeTypography; | ||
sizes: ThemeSizes; | ||
variants: ThemeVariants; | ||
} | ||
export interface DefaultTheme extends Theme {} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import React, { useState, useCallback } from 'react'; | ||
import { css } from 'styled-components'; | ||
import Collapse from '../Collapse'; | ||
import { createComponent } from '../utils'; | ||
import { Box } from '../Box'; | ||
import { Icon } from '../Icon'; | ||
import { Flex } from '../Flex'; | ||
|
||
const AccordionContainer = createComponent({ | ||
name: 'Accordion', | ||
}); | ||
|
||
const AccordionItemContainer = createComponent({ | ||
name: 'AccordionItem', | ||
}); | ||
|
||
const AccordionHeader = createComponent({ | ||
name: 'AccordionItemHeader', | ||
tag: 'header', | ||
style: css` | ||
padding: 0.75rem 1rem; | ||
cursor: pointer; | ||
`, | ||
}); | ||
|
||
const AccordionTitle = createComponent({ | ||
name: 'AccordionItemTitle', | ||
tag: 'span', | ||
style: css``, | ||
}); | ||
|
||
const AccordionIcon = createComponent<{ isOpen?: boolean }, typeof Icon>({ | ||
name: 'AccordionItemIcon', | ||
as: Icon, | ||
style: ({ isOpen }) => css` | ||
transition: 175ms transform; | ||
transform: rotate(${isOpen ? 90 : 0}deg); | ||
`, | ||
}); | ||
|
||
const AccordionContent = createComponent({ | ||
name: 'AccordionItemContent', | ||
}); | ||
|
||
interface AccordionItemProps extends Partial<Pick<AccordionProps, 'contentContainerStyle'>> { | ||
title: string; | ||
isOpen?: boolean; | ||
content?: React.ReactNode | string; | ||
onToggle?: () => void; | ||
renderHeader?: (p: Pick<AccordionItemProps, 'isOpen' | 'title' | 'onToggle'>) => React.ReactNode; | ||
renderContent?: (p: Pick<AccordionItemProps, 'isOpen' | 'content'>) => React.ReactNode; | ||
} | ||
|
||
const AccordionItem: React.FC<AccordionItemProps> = ({ | ||
isOpen, | ||
title, | ||
content, | ||
contentContainerStyle, | ||
renderHeader, | ||
renderContent, | ||
onToggle, | ||
}) => ( | ||
<AccordionItemContainer> | ||
<Collapse | ||
isOpen={isOpen} | ||
renderTrigger={() => | ||
renderHeader ? ( | ||
renderHeader({ isOpen, title, onToggle }) | ||
) : ( | ||
<AccordionHeader onClick={onToggle}> | ||
<Flex> | ||
<Box flex={1}> | ||
<AccordionTitle>{title}</AccordionTitle> | ||
</Box> | ||
<AccordionIcon name="chevron-right" isOpen={isOpen} /> | ||
</Flex> | ||
</AccordionHeader> | ||
) | ||
}> | ||
{renderContent ? ( | ||
renderContent({ isOpen, content }) | ||
) : ( | ||
<AccordionContent style={contentContainerStyle}>{content}</AccordionContent> | ||
)} | ||
</Collapse> | ||
</AccordionItemContainer> | ||
); | ||
|
||
export interface AccordionProps { | ||
items: AccordionItemProps[]; | ||
solo?: boolean; | ||
contentContainerStyle?: React.CSSProperties; | ||
} | ||
|
||
export interface AccordionStaticMembers { | ||
Item: typeof AccordionItem; | ||
} | ||
|
||
const Accordion: React.FC<AccordionProps> & AccordionStaticMembers = ({ | ||
items, | ||
solo, | ||
contentContainerStyle, | ||
children, | ||
}) => { | ||
const [openList, setOpenList] = useState<number[]>([]); | ||
|
||
const handleItemToggle = useCallback( | ||
(idx: number) => { | ||
if (openList.indexOf(idx) >= 0) setOpenList(openList.filter(i => i !== idx)); | ||
else setOpenList(solo ? [idx] : [...openList, idx]); | ||
}, | ||
[solo, openList] | ||
); | ||
|
||
return ( | ||
<AccordionContainer> | ||
{children || | ||
items.map((item, i) => ( | ||
<AccordionItem | ||
key={item.title} | ||
contentContainerStyle={contentContainerStyle} | ||
{...item} | ||
isOpen={openList.indexOf(i) >= 0} | ||
onToggle={() => handleItemToggle(i)} | ||
/> | ||
))} | ||
</AccordionContainer> | ||
); | ||
}; | ||
|
||
Accordion.Item = AccordionItem; | ||
|
||
export default Accordion; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.