diff --git a/scripts/insert-react-docgen-typescript.js b/scripts/insert-react-docgen-typescript.js index 499566385..4a21850f6 100644 --- a/scripts/insert-react-docgen-typescript.js +++ b/scripts/insert-react-docgen-typescript.js @@ -86,17 +86,16 @@ function insertTypescriptDocs(options) { const parser = withDefaultConfig(parserOptions); const getDirectories = (folder, excludeFiles, repoDir, newNodes) => { - const items = fs.readdirSync(folder, { withFileTypes: true }); + const items = fs.readdirSync(folder, { withFileTypes: true }) + .filter(entry => !excludeFiles.some(excluded => entry.name.match(new RegExp(excluded)))); const files = items.filter(entry => !entry.isDirectory()); for (const entry of files) { - if (excludeFiles.indexOf(entry.name) === -1) { - const propTables = parser.parse(path.join(folder, entry.name)); - if (propTables && propTables.length > 0) { - propTables.forEach(propTable => { - const propNodes = propsToMDNodes(propTable, path.join(repoDir,entry.name )); - newNodes.push.apply(newNodes, propNodes); - }) - } + const propTables = parser.parse(path.join(folder, entry.name)); + if (propTables && propTables.length > 0) { + propTables.forEach(propTable => { + const propNodes = propsToMDNodes(propTable, path.join(repoDir,entry.name )); + newNodes.push.apply(newNodes, propNodes); + }) } }; items.filter(entry => entry.isDirectory()) diff --git a/ui/blocks/src/ComponentSource/ComponentSource.tsx b/ui/blocks/src/ComponentSource/ComponentSource.tsx index 98a6c241a..87341761e 100644 --- a/ui/blocks/src/ComponentSource/ComponentSource.tsx +++ b/ui/blocks/src/ComponentSource/ComponentSource.tsx @@ -4,13 +4,16 @@ import { ComponentsContainer } from '../context/components/ComponentsContainer'; import { ComponentInputProps } from '../context/components/ComponentsContext'; import { ThemeContext, - Source as SourceBlock, + Source, SourceProps, + BlockContainer, + BlockContainerProps, } from '@component-controls/components'; import { repositoryActions } from '../utils/repositoryActions'; export type ComponentSourceProps = ComponentInputProps & - Omit; + Omit & + BlockContainerProps; /** * Displays import statement for a component as well as the component file source code @@ -21,6 +24,7 @@ export type ComponentSourceProps = ComponentInputProps & export const ComponentSource: FC = ({ of, actions, + title, ...rest }) => { return ( @@ -64,9 +68,11 @@ export const ComponentSource: FC = ({ allActions.push.apply(allActions, actions); } return ( - - {showFileSource ? component?.source : source} - + + + {showFileSource ? component?.source : source} + + ); }} diff --git a/ui/blocks/src/ControlsTable/ControlsTable.tsx b/ui/blocks/src/ControlsTable/ControlsTable.tsx index ecf242feb..39b8fd1e2 100644 --- a/ui/blocks/src/ControlsTable/ControlsTable.tsx +++ b/ui/blocks/src/ControlsTable/ControlsTable.tsx @@ -13,6 +13,7 @@ import { } from '@component-controls/core'; import { BlockContainer, + ActionContainer, Tab, Tabs, TabList, @@ -97,32 +98,34 @@ export const ControlsTable: FC - - {groupedItems.length === 1 ? ( - - ) : ( - - + + + + {groupedItems.length === 1 ? ( + + ) : ( + + + {groupedItems.map(item => ( + {item.label} + ))} + {groupedItems.map(item => ( - {item.label} + + + ))} - - {groupedItems.map(item => ( - - - - ))} - - )} - + + )} + + ); } diff --git a/ui/blocks/src/PropsTable/block/BlockPropsTable.tsx b/ui/blocks/src/PropsTable/block/BlockPropsTable.tsx index 76e8ec286..52ba7f888 100644 --- a/ui/blocks/src/PropsTable/block/BlockPropsTable.tsx +++ b/ui/blocks/src/PropsTable/block/BlockPropsTable.tsx @@ -2,11 +2,15 @@ import React, { FC, useState } from 'react'; import { BlockContainer, BlockContainerProps, + ActionContainer, + ActionContainerProps, ActionItem, } from '@component-controls/components'; import { PropsTable, PropsTableProps } from '../plain'; -export type BlockPropsTableProps = PropsTableProps & BlockContainerProps; +export type BlockPropsTableProps = PropsTableProps & + BlockContainerProps & + ActionContainerProps; export const BlockPropsTable: FC = ({ title, @@ -24,20 +28,10 @@ export const BlockPropsTable: FC = ({ allActions.push.apply(allActions, actions); } // add some padding for the actions bar - const propsTable = ( - th': { - paddingTop: 26, - }, - }} - filtering={filtering} - {...rest} - /> - ); + const propsTable = ; return propsTable ? ( - - {propsTable} + + {propsTable} ) : null; }; diff --git a/ui/blocks/src/StorySource/PureStorySource.stories.tsx b/ui/blocks/src/StorySource/PureStorySource.stories.tsx index fc2c60a2d..0549b15ed 100644 --- a/ui/blocks/src/StorySource/PureStorySource.stories.tsx +++ b/ui/blocks/src/StorySource/PureStorySource.stories.tsx @@ -11,7 +11,7 @@ export default { component: PureStorySource, }; -export const simpleSource = ({ +export const overview = ({ language, children, theme, @@ -58,7 +58,7 @@ const languages: string[] = [ 'yaml', ]; -simpleSource.story = { +overview.story = { controls: { language: { type: 'options', options: languages, value: 'jsx' }, children: { diff --git a/ui/blocks/src/StorySource/TaggedSource.tsx b/ui/blocks/src/StorySource/TaggedSource.tsx index 42ccc63f2..662a12fe5 100644 --- a/ui/blocks/src/StorySource/TaggedSource.tsx +++ b/ui/blocks/src/StorySource/TaggedSource.tsx @@ -8,7 +8,12 @@ import { } from '@component-controls/specification'; import { Styled } from 'theme-ui'; import { transparentize } from 'polished'; -import { Source, SourceProps } from '@component-controls/components'; +import { + Source, + SourceProps, + BlockContainer, + BlockContainerProps, +} from '@component-controls/components'; interface ArgumentLocations { name: string; @@ -36,109 +41,116 @@ const getArgumentsLocations = (args: StoryArguments): ArgumentLocations[] => { }, []); }; -export type TaggedSourceProps = SourceProps & { +export type TaggedSourceProps = { /** * a list of story arguments accepted by Source * this is used to syntax-highlight the arguments * and their usage */ args?: StoryArguments; -}; +} & SourceProps & + BlockContainerProps; export const TaggedSource: React.FC = ({ args, theme, + title, ...rest }) => { const tags: (ArgumentLocations & { color?: string })[] | undefined = args ? getArgumentsLocations(args) : undefined; return ( - { - if (tags) { - tags.forEach((tag, index) => { - let color: string; - const colorIdx = index % (theme.styles.length - 1); - const style = theme.styles[colorIdx]; - color = style.style.color || theme.plain.color || '#fff'; - tag.color = color; - }); - } - return ( - - {tokens.map((line, i: number) => ( -
- {(() => { - let column = 0; - return line.map((token, key) => { - const tokenTrim = token.content.trim(); - const param = tags - ? tags.find(tag => { - if (tag.name === tokenTrim) { - return tag.locs.find( - loc => - loc.start.line === i && - loc.start.column >= column && - loc.start.column <= - column + token.content.length, - ); - } - return false; - }) - : null; + + { + if (tags) { + tags.forEach((tag, index) => { + let color: string; + const colorIdx = index % (theme.styles.length - 1); + const style = theme.styles[colorIdx]; + color = style.style.color || theme.plain.color || '#fff'; + tag.color = color; + }); + } + return ( + + {tokens.map((line, i: number) => ( +
+ {(() => { + let column = 0; + return line.map((token, key) => { + const tokenTrim = token.content.trim(); + const param = tags + ? tags.find(tag => { + if (tag.name === tokenTrim) { + return tag.locs.find( + loc => + loc.start.line === i && + loc.start.column >= column && + loc.start.column <= + column + token.content.length, + ); + } + return false; + }) + : null; - column += token.content.length; - if (param) { - const splitToken = getTokenProps({ - token, - key, - }).children.split(/(\s+)/); + column += token.content.length; + if (param) { + const splitToken = getTokenProps({ + token, + key, + }).children.split(/(\s+)/); - return splitToken.map(s => - s.trim().length ? ( - - {s} - - ) : ( - s - ), + return splitToken.map(s => + s.trim().length ? ( + + {s} + + ) : ( + s + ), + ); + } + return ( + ); - } - return ( - - ); - }); - })()} -
- ))} -
- ); - }} - /> + }); + })()} +
+ ))} +
+ ); + }} + /> +
); }; diff --git a/ui/blocks/src/Subtitle/Subtitle.stories.tsx b/ui/blocks/src/Subtitle/Subtitle.stories.tsx index 45e56c9e4..d50b7ec4d 100644 --- a/ui/blocks/src/Subtitle/Subtitle.stories.tsx +++ b/ui/blocks/src/Subtitle/Subtitle.stories.tsx @@ -7,13 +7,13 @@ export default { component: Subtitle, }; -export const simple = () => ( +export const overview = () => ( ); -simple.story = { +overview.story = { parameters: { componentSubtitle: 'This is subtitle', }, diff --git a/ui/components/README.md b/ui/components/README.md index 81422ea1b..672e4aa75 100644 --- a/ui/components/README.md +++ b/ui/components/README.md @@ -5,33 +5,20 @@ - [List of components](#list-of-components) - [ActionBar](#insactionbarins) - [ActionContainer](#insactioncontainerins) - - [overview](#insoverviewins) - [BlockContainer](#insblockcontainerins) - - [simple](#inssimpleins) - [Collapsible](#inscollapsibleins) - - [simple](#inssimpleins-1) - [ExternalLink](#insexternallinkins) - [FlexContainer](#insflexcontainerins) - [Markdown](#insmarkdownins) - - [simple](#inssimpleins-2) - - [Wrapper](#inswrapperins) - - [Arrow](#insarrowins) - [Popover](#inspopoverins) - - [simpleSource](#inssimplesourceins) - [Source](#inssourceins) - - [simple](#inssimpleins-3) - [Subtitle](#inssubtitleins) - - [simpleSource](#inssimplesourceins-1) - [SyntaxHighlighter](#inssyntaxhighlighterins) - [Table](#instableins) - - [GlobalFilter](#insglobalfilterins) - - [useExpanderColumn](#insuseexpandercolumnins) - - [useTableLayout](#insusetablelayoutins) - [Tab](#instabins) - [Tabs](#instabsins) - [TabList](#instablistins) - [TabPanel](#instabpanelins) - - [simple](#inssimpleins-4) - [Title](#institleins) - [Toggle](#instoggleins) @@ -55,7 +42,7 @@ The third-libraries used include in no particular order: # List of components - + @@ -83,16 +70,6 @@ _ActionContainer [source code](https:/github.com/ccontrols/component-controls/bl optional actions provided to the component -## overview - -_overview [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/BlockContainer/BlockContainer.stories.tsx)_ - -**Properties:** - -- **title**? : _string_ - - optional section title for the block - ## BlockContainer a collapsible block with a title. The title creates also an attribute id and an octicon for github style navigation. @@ -105,24 +82,6 @@ _BlockContainer [source code](https:/github.com/ccontrols/component-controls/blo optional section title for the block -## simple - -_simple [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Collapsible/Collapsible.stories.tsx)_ - -**Properties:** - -- **animateOpacity**? : _boolean_ -- **animationStateClasses**? : _AnimationStateClasses_ -- **applyInlineTransitions**? : _boolean_ -- **contentClassName**? : _string_ -- **delay**? : _number_ -- **duration**? : _number_ -- **easing**? : _string_ -- **height**? : _ReactText_ -- **onAnimationEnd**? : _(props: { newHeight: number; }) => void_ -- **onAnimationStart**? : _(props: { newHeight: number; }) => void_ -- **isOpen** : _boolean_ - ## Collapsible _Collapsible [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Collapsible/Collapsible.tsx)_ @@ -141,14 +100,6 @@ _Collapsible [source code](https:/github.com/ccontrols/component-controls/blob/m - **onAnimationStart**? : _(props: { newHeight: number; }) => void_ - **isOpen** : _boolean_ -## simple - -_simple [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/ExternalLink/ExternalLink.stories.tsx)_ - -**Properties:** - -- **ref**? : _((instance: HTMLAnchorElement) => void) | RefObject<HTMLAnchorElement>_ - ## ExternalLink _ExternalLink [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/ExternalLink/ExternalLink.tsx)_ @@ -181,30 +132,6 @@ _Markdown [source code](https:/github.com/ccontrols/component-controls/blob/mast components to customize the markdown display -## simple - -_simple [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Popover/Popover.stories.tsx)_ - -## Wrapper - -_Wrapper [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Popover/Popover.tsx)_ - -**Properties:** - -- **placement**? : _string_ -- **borderColor** : _string_ -- **theme**? : _object_ - -## Arrow - -_Arrow [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Popover/Popover.tsx)_ - -**Properties:** - -- **placement**? : _string_ -- **borderColor** : _string_ -- **theme**? : _object_ - ## Popover A Popover container that is triggered by a click, or hover @@ -212,37 +139,6 @@ used to display enhanced information that could not fit into the main scren _Popover [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Popover/Popover.tsx)_ -## simpleSource - -_simpleSource [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Source/Source.stories.tsx)_ - -**Properties:** - -- **children** : _any_ - - source code to be displayed -- **theme**? : _PrismTheme_ - - optional theme provided to the component -- **language**? : _Language_ - - code lnguage used, by default "jsx" -- **renderFn**? : _(props: RenderProps, other: { theme: PrismTheme; }) => ReactNode_ - - custom function to render the source code -- **dark**? : _boolean_ - - used to specify a "dark" color theme - applcable only if no custom theme prop is provided -- **style**? : _any_ - - css styles for the container -- **as**? : _any_ - - syntax container as element -- **actions**? : _ActionItem\[]_ - - optional actions provided to the component - ## Source Source component used to display source code @@ -276,10 +172,6 @@ _Source [source code](https:/github.com/ccontrols/component-controls/blob/master optional actions provided to the component -## simple - -_simple [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Subtitle/Subtitle.stories.tsx)_ - ## Subtitle _Subtitle [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Subtitle/Subtitle.tsx)_ @@ -288,34 +180,6 @@ _Subtitle [source code](https:/github.com/ccontrols/component-controls/blob/mast - **ref**? : _((instance: HTMLHeadingElement) => void) | RefObject<HTMLHeadingElement>_ -## simpleSource - -_simpleSource [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx)_ - -**Properties:** - -- **children** : _any_ - - source code to be displayed -- **theme**? : _PrismTheme_ - - optional theme provided to the component -- **language**? : _Language_ - - code lnguage used, by default "jsx" -- **renderFn**? : _(props: RenderProps, other: { theme: PrismTheme; }) => ReactNode_ - - custom function to render the source code -- **dark**? : _boolean_ - - used to specify a "dark" color theme - applcable only if no custom theme prop is provided -- **style**? : _any_ - - css styles for the container -- **as**? : _any_ - - syntax container as element - ## SyntaxHighlighter Syntax highlighter component @@ -362,23 +226,6 @@ _Table [source code](https:/github.com/ccontrols/component-controls/blob/master/ - **hiddenColumns**? : _string\[]_ - **expanded**? : _{ \[key: string]: boolean; }_ -## GlobalFilter - -_GlobalFilter [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Table/TableFilter.tsx)_ - -**Properties:** - -- **globalFilter**? : _string | ((rows: Row<any>\[], columnIds: string\[], filterValue: any) => Row<any>\[])_ -- **itemsLabel** : _string_ - -## useExpanderColumn - -_useExpanderColumn [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Table/TableGrouping.tsx)_ - -## useTableLayout - -_useTableLayout [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Table/useTableLayout.ts)_ - ## Tab _Tab [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Tabs/Tabs.tsx)_ @@ -395,10 +242,6 @@ _TabList [source code](https:/github.com/ccontrols/component-controls/blob/maste _TabPanel [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Tabs/Tabs.tsx)_ -## simple - -_simple [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Title/Title.stories.tsx)_ - ## Title _Title [source code](https:/github.com/ccontrols/component-controls/blob/master/ui/components/src/Title/Title.tsx)_ diff --git a/ui/components/src/ActionContainer/ActionContainer.tsx b/ui/components/src/ActionContainer/ActionContainer.tsx index 7126055fa..efd99d202 100644 --- a/ui/components/src/ActionContainer/ActionContainer.tsx +++ b/ui/components/src/ActionContainer/ActionContainer.tsx @@ -32,8 +32,8 @@ export const ActionContainer: FC = ({ 0.9, theme.colors?.text as string, )} 0 0 0 1px`, - '*:first-child': { - paddingTop: 3, + 'div:first-child, svg:first-child': { + paddingTop: '20px', }, }} > diff --git a/ui/components/src/BlockContainer/BlockContainer.tsx b/ui/components/src/BlockContainer/BlockContainer.tsx index af69335be..81cc9d4d7 100644 --- a/ui/components/src/BlockContainer/BlockContainer.tsx +++ b/ui/components/src/BlockContainer/BlockContainer.tsx @@ -1,6 +1,6 @@ /** @jsx jsx */ import React, { FC } from 'react'; -import { jsx, Flex, Link, Divider, Box, useThemeUI } from 'theme-ui'; +import { jsx, Flex, Link, Divider, Box } from 'theme-ui'; import Octicon, { Link as LinkIcon, ChevronRight, diff --git a/ui/components/src/Collapsible/Collapsible.stories.tsx b/ui/components/src/Collapsible/Collapsible.stories.tsx index 896a462d6..58b87b65d 100644 --- a/ui/components/src/Collapsible/Collapsible.stories.tsx +++ b/ui/components/src/Collapsible/Collapsible.stories.tsx @@ -7,7 +7,7 @@ export default { component: Collapsible, }; -export const simple = ({ easing }: CollapsibleProps) => { +export const overview = ({ easing }: CollapsibleProps) => { const [isOpen, setIsOpen] = React.useState(false); return ( @@ -21,7 +21,7 @@ export const simple = ({ easing }: CollapsibleProps) => { ); }; -simple.story = { +overview.story = { parameters: { addonControls: { smart: false, diff --git a/ui/components/src/ExternalLink/ExternalLink.stories.tsx b/ui/components/src/ExternalLink/ExternalLink.stories.tsx index 8bac55636..1ca6f9cd3 100644 --- a/ui/components/src/ExternalLink/ExternalLink.stories.tsx +++ b/ui/components/src/ExternalLink/ExternalLink.stories.tsx @@ -6,11 +6,11 @@ export default { component: ExternalLink, }; -export const simple = ({ href }: ExternalLinkProps) => { +export const overview = ({ href }: ExternalLinkProps) => { return {href}; }; -simple.story = { +overview.story = { parameters: { addonControls: { smart: false, diff --git a/ui/components/src/Markdown/Markdown.stories.tsx b/ui/components/src/Markdown/Markdown.stories.tsx index af35d71bf..f82cdacff 100644 --- a/ui/components/src/Markdown/Markdown.stories.tsx +++ b/ui/components/src/Markdown/Markdown.stories.tsx @@ -7,7 +7,7 @@ export default { component: Markdown, }; -export const simple = () => ( +export const overview = () => ( {` # Header H1 diff --git a/ui/components/src/Popover/Popover.stories.tsx b/ui/components/src/Popover/Popover.stories.tsx index 1645a305e..e1c871d64 100644 --- a/ui/components/src/Popover/Popover.stories.tsx +++ b/ui/components/src/Popover/Popover.stories.tsx @@ -7,7 +7,7 @@ export default { component: Popover, }; -export const simple = ({ placement, trigger }: PopoverProps) => { +export const overview = ({ placement, trigger }: PopoverProps) => { const [isOpen, setIsOpen] = React.useState(false); return ( { ); }; -simple.story = { +overview.story = { controls: { placement: { type: 'options', diff --git a/ui/components/src/Popover/Popover.tsx b/ui/components/src/Popover/Popover.tsx index 7fa0279cb..1408d115d 100644 --- a/ui/components/src/Popover/Popover.tsx +++ b/ui/components/src/Popover/Popover.tsx @@ -1,85 +1,11 @@ import React, { FC } from 'react'; -import styled from '@emotion/styled'; import TooltipTrigger from 'react-popper-tooltip'; import { TooltipTriggerProps } from 'react-popper-tooltip/dist/types'; import { Box } from 'theme-ui'; +import { Arrow, Wrapper } from './PopoverUtils'; export type PopoverProps = Omit, 'children'>; -const SPACING = 8; - -const match = ( - requested: string, - actual: string, - value: number | string, - fallback: number | string = 0, -) => (actual.split('-')[0] === requested ? value : fallback); - -export const Wrapper = styled.div<{ - placement: string; - borderColor: string; - hidden: boolean; -}>(({ placement, borderColor, hidden }) => ({ - display: hidden ? 'none' : 'inline-block', - background: 'white', - marginTop: `${match('bottom', placement, SPACING + 2, 0)}px`, - marginLeft: `${match('right', placement, SPACING + 2, 0)}px`, - marginRight: `${match('left', placement, SPACING + 2, 0)}px`, - filter: ` - drop-shadow(0px 5px 5px rgba(0,0,0,0.05)) - drop-shadow(0 1px 3px rgba(0,0,0,0.1)) -`, - borderRadius: 8, - fontSize: 12, - border: `1px solid ${borderColor}`, -})); -export const Arrow = styled.div<{ placement: string; borderColor: string }>( - ({ placement, borderColor }) => ({ - position: 'absolute', - borderStyle: 'solid', - background: 'white', - marginBottom: `${match('top', placement, '0', SPACING)}px`, - marginTop: `${match('bottom', placement, '0', SPACING)}px`, - marginRight: `${match('left', placement, '0', SPACING)}px`, - marginLeft: `${match('right', placement, '0', SPACING)}px`, - - bottom: `${match('top', placement, SPACING * -1, 'auto')}px`, - top: `${match('bottom', placement, SPACING * -1, 'auto')}px`, - right: `${match('left', placement, SPACING * -1, 'auto')}px`, - left: `${match('right', placement, SPACING * -1, 'auto')}px`, - - borderBottomWidth: `${match('top', placement, '0', SPACING)}px`, - borderTopWidth: `${match('bottom', placement, '0', SPACING)}px`, - borderRightWidth: `${match('left', placement, '0', SPACING)}px`, - borderLeftWidth: `${match('right', placement, '0', SPACING)}px`, - - borderTopColor: match( - 'top', - placement, - borderColor, - 'transparent', - ) as string, - borderBottomColor: match( - 'bottom', - placement, - borderColor, - 'transparent', - ) as string, - borderLeftColor: match( - 'left', - placement, - borderColor, - 'transparent', - ) as string, - borderRightColor: match( - 'right', - placement, - borderColor, - 'transparent', - ) as string, - }), -); - /** * A Popover container that is triggered by a click, or hover * used to display enhanced information that could not fit into the main scren diff --git a/ui/components/src/Popover/PopoverUtils.tsx b/ui/components/src/Popover/PopoverUtils.tsx new file mode 100644 index 000000000..d3a4e318c --- /dev/null +++ b/ui/components/src/Popover/PopoverUtils.tsx @@ -0,0 +1,76 @@ +import styled from '@emotion/styled'; + +const SPACING = 8; + +const match = ( + requested: string, + actual: string, + value: number | string, + fallback: number | string = 0, +) => (actual.split('-')[0] === requested ? value : fallback); + +export const Arrow = styled.div<{ placement: string; borderColor: string }>( + ({ placement, borderColor }) => ({ + position: 'absolute', + borderStyle: 'solid', + background: 'white', + marginBottom: `${match('top', placement, '0', SPACING)}px`, + marginTop: `${match('bottom', placement, '0', SPACING)}px`, + marginRight: `${match('left', placement, '0', SPACING)}px`, + marginLeft: `${match('right', placement, '0', SPACING)}px`, + + bottom: `${match('top', placement, SPACING * -1, 'auto')}px`, + top: `${match('bottom', placement, SPACING * -1, 'auto')}px`, + right: `${match('left', placement, SPACING * -1, 'auto')}px`, + left: `${match('right', placement, SPACING * -1, 'auto')}px`, + + borderBottomWidth: `${match('top', placement, '0', SPACING)}px`, + borderTopWidth: `${match('bottom', placement, '0', SPACING)}px`, + borderRightWidth: `${match('left', placement, '0', SPACING)}px`, + borderLeftWidth: `${match('right', placement, '0', SPACING)}px`, + + borderTopColor: match( + 'top', + placement, + borderColor, + 'transparent', + ) as string, + borderBottomColor: match( + 'bottom', + placement, + borderColor, + 'transparent', + ) as string, + borderLeftColor: match( + 'left', + placement, + borderColor, + 'transparent', + ) as string, + borderRightColor: match( + 'right', + placement, + borderColor, + 'transparent', + ) as string, + }), +); + +export const Wrapper = styled.div<{ + placement: string; + borderColor: string; + hidden: boolean; +}>(({ placement, borderColor, hidden }) => ({ + display: hidden ? 'none' : 'inline-block', + background: 'white', + marginTop: `${match('bottom', placement, SPACING + 2, 0)}px`, + marginLeft: `${match('right', placement, SPACING + 2, 0)}px`, + marginRight: `${match('left', placement, SPACING + 2, 0)}px`, + filter: ` + drop-shadow(0px 5px 5px rgba(0,0,0,0.05)) + drop-shadow(0 1px 3px rgba(0,0,0,0.1)) +`, + borderRadius: 8, + fontSize: 12, + border: `1px solid ${borderColor}`, +})); diff --git a/ui/components/src/Source/Source.stories.tsx b/ui/components/src/Source/Source.stories.tsx index 6aab77adc..e7dd15169 100644 --- a/ui/components/src/Source/Source.stories.tsx +++ b/ui/components/src/Source/Source.stories.tsx @@ -17,7 +17,7 @@ const source = `export const sample = () => { /> ); };`; -export const simpleSource = ({ language, children, dark }: SourceProps) => { +export const overview = ({ language, children, dark }: SourceProps) => { return ( {children} @@ -60,7 +60,7 @@ const languages: string[] = [ 'yaml', ]; -simpleSource.story = { +overview.story = { controls: { language: { type: 'options', options: languages, value: 'jsx' }, dark: { type: 'boolean' }, diff --git a/ui/components/src/Source/Source.tsx b/ui/components/src/Source/Source.tsx index ecc4e065a..8a5b55ded 100644 --- a/ui/components/src/Source/Source.tsx +++ b/ui/components/src/Source/Source.tsx @@ -39,7 +39,7 @@ export const Source: FC = ({ as={as} {...props} style={{ - padding: '16px 10px 10px', + padding: '0 10px 10px', display: 'block', }} > diff --git a/ui/components/src/Subtitle/Subtitle.stories.tsx b/ui/components/src/Subtitle/Subtitle.stories.tsx index 699db1a9a..3b6cfbc4f 100644 --- a/ui/components/src/Subtitle/Subtitle.stories.tsx +++ b/ui/components/src/Subtitle/Subtitle.stories.tsx @@ -6,11 +6,11 @@ export default { component: Subtitle, }; -export const simple = ({ children }: { children: React.ReactNode }) => { +export const overview = ({ children }: { children: React.ReactNode }) => { return {children}; }; -simple.story = { +overview.story = { parameters: { componentSubtitle: 'This is subtitle', }, diff --git a/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx b/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx index 2858ef769..e6f94f4f3 100644 --- a/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx +++ b/ui/components/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx @@ -8,11 +8,11 @@ export default { }; const source = `import { Button } from 'theme-ui';`; -export const simpleSource = ({ children, dark }: SyntaxHighlighterProps) => { +export const overview = ({ children, dark }: SyntaxHighlighterProps) => { return {children}; }; -simpleSource.story = { +overview.story = { controls: { children: { type: 'text', diff --git a/ui/components/src/Table/Table.stories.tsx b/ui/components/src/Table/Table.stories.tsx index 19959db46..1c4998e98 100644 --- a/ui/components/src/Table/Table.stories.tsx +++ b/ui/components/src/Table/Table.stories.tsx @@ -49,7 +49,7 @@ const mockData = () => { })); }; -export const main = () => { +export const overview = () => { const data = React.useMemo(mockData, []); return ( diff --git a/ui/components/src/Title/Title.stories.tsx b/ui/components/src/Title/Title.stories.tsx index 9c6e9973a..17f8b5c19 100644 --- a/ui/components/src/Title/Title.stories.tsx +++ b/ui/components/src/Title/Title.stories.tsx @@ -6,11 +6,11 @@ export default { component: Title, }; -export const simple = ({ children }: { children: React.ReactNode }) => { +export const overview = ({ children }: { children: React.ReactNode }) => { return {children}; }; -simple.story = { +overview.story = { controls: { children: { type: 'text', value: 'Title text' }, }, diff --git a/ui/components/src/index.ts b/ui/components/src/index.ts index 966040e0d..1ba03f870 100644 --- a/ui/components/src/index.ts +++ b/ui/components/src/index.ts @@ -1,4 +1,5 @@ export * from './ActionBar'; +export * from './ActionContainer'; export * from './BlockContainer'; export * from './Collapsible'; export * from './ExternalLink';