-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
05a7ece
commit 9aac591
Showing
9 changed files
with
565 additions
and
319 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,74 @@ | ||
import cn from 'classnames' | ||
import { createUseStyles } from 'react-jss' | ||
import { faCopy } from '@fortawesome/pro-regular-svg-icons' | ||
import { generateThemedControlsStyles } from './utils' | ||
import { IconButton } from 'components/IconButton' | ||
import { Tooltip } from 'components/Tooltip' | ||
import React, { FC } from 'react' | ||
import { styleguide, ThemeType } from 'components/assets/styles' | ||
|
||
const { borderRadius, spacing } = styleguide | ||
|
||
const { light, dark } = ThemeType | ||
|
||
const useStyles = createUseStyles({ | ||
codeControls: { | ||
...generateThemedControlsStyles(light), | ||
borderRadius, | ||
padding: `${spacing.xs}px ${spacing.s}px`, | ||
position: 'absolute', | ||
right: spacing['s+'], | ||
top: spacing['s+'], | ||
zIndex: 1 | ||
}, | ||
iconButton: { | ||
padding: { | ||
left: spacing.s, | ||
right: spacing.s | ||
} | ||
}, | ||
// eslint-disable-next-line sort-keys | ||
'@global': { | ||
[`.${dark}`]: { | ||
'& $codeControls': generateThemedControlsStyles(dark) | ||
} | ||
} | ||
}) | ||
|
||
// This is left as an object so more controls (e.g. download) can be added later | ||
export interface DisplayCodeControls { | ||
copy?: boolean | ||
} | ||
|
||
interface Props { | ||
classes?: string[] | ||
displayControls?: DisplayCodeControls | ||
isCopied?: boolean | ||
onClickCopyCode: () => void | ||
} | ||
|
||
export const CodeControls: FC<Props> = ({ | ||
classes = [], | ||
displayControls = {}, | ||
isCopied = false, | ||
onClickCopyCode | ||
}: Props) => { | ||
const compClasses = useStyles() | ||
|
||
const { copy = true } = displayControls | ||
|
||
return ( | ||
<div className={cn(compClasses.codeControls, classes)}> | ||
{copy && ( | ||
<Tooltip placement='top' title={isCopied ? 'Copied!' : 'Copy'}> | ||
<IconButton | ||
classes={[compClasses.iconButton]} | ||
icon={faCopy} | ||
onClick={onClickCopyCode} | ||
size={14} | ||
/> | ||
</Tooltip> | ||
)} | ||
</div> | ||
) | ||
} |
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,45 @@ | ||
import cn from 'classnames' | ||
import { createUseStyles } from 'react-jss' | ||
import { motion } from 'framer-motion' | ||
import { styleguide } from 'components/assets/styles' | ||
import { TabConfig } from '.' | ||
import React, { FC } from 'react' | ||
|
||
const { font, spacing } = styleguide | ||
|
||
const useStyles = createUseStyles({ | ||
tabPane: { | ||
...font.body, | ||
display: ({ isActive }) => (isActive ? 'block' : 'none'), | ||
padding: `${spacing.m}px ${spacing.l}px` | ||
} | ||
}) | ||
|
||
interface TabPaneProps { | ||
isActive: boolean | ||
tabConfigItem: TabConfig | ||
} | ||
|
||
const [ACTIVE, INACTIVE] = ['active', 'inactive'] | ||
|
||
const TabPane: FC<TabPaneProps> = ({ | ||
isActive, | ||
tabConfigItem: { classes = [], render } | ||
}: TabPaneProps) => { | ||
const compClasses = useStyles({ isActive }) | ||
|
||
return ( | ||
<motion.section | ||
animate={isActive ? ACTIVE : INACTIVE} | ||
transition={{ duration: 0.5 }} | ||
variants={{ | ||
[ACTIVE]: { opacity: 1 }, | ||
[INACTIVE]: { opacity: 0 } | ||
}} | ||
> | ||
<div className={cn(compClasses.tabPane, classes)}>{render()}</div> | ||
</motion.section> | ||
) | ||
} | ||
|
||
export default TabPane |
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.