-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from storybookjs/clipboard
Clipboard components
- Loading branch information
Showing
10 changed files
with
214 additions
and
30 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
13 changes: 8 additions & 5 deletions
13
src/components/Clipboard.stories.js → ...omponents/clipboard/Clipboard.stories.tsx
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,20 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import React from 'react'; | ||
|
||
import { ClipboardCode } from './ClipboardCode'; | ||
|
||
export default { | ||
title: 'Design System/Clipboard/ClipboardCode', | ||
}; | ||
|
||
export const Default = () => ( | ||
<div style={{ padding: '3em', width: 300 }}> | ||
<ClipboardCode code="git checkout master" /> | ||
</div> | ||
); | ||
|
||
export const Wrapped = () => ( | ||
<div style={{ padding: '3em', width: 250 }}> | ||
<ClipboardCode code="git checkout master" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { ClipboardIcon } from './ClipboardIcon'; | ||
|
||
const Container = styled.div` | ||
position: relative; | ||
`; | ||
|
||
const Code = styled.pre` | ||
width: 100%; | ||
display: block; | ||
margin: 0; | ||
padding-right: 32px; | ||
overflow: hidden; | ||
`; | ||
|
||
const StyledClipboardIcon = styled(ClipboardIcon)` | ||
position: absolute; | ||
top: 8px; | ||
right: 8px; | ||
`; | ||
|
||
interface ClipboardCodeProps { | ||
code: string; | ||
} | ||
|
||
export const ClipboardCode = ({ code, ...props }: ClipboardCodeProps) => ( | ||
<Container> | ||
<Code id="clipboard-code" {...props}> | ||
{code} | ||
</Code> | ||
<StyledClipboardIcon toCopy={code} /> | ||
</Container> | ||
); |
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,13 @@ | ||
import React from 'react'; | ||
|
||
import { ClipboardIcon } from './ClipboardIcon'; | ||
|
||
export default { | ||
title: 'Design System/Clipboard/ClipboardIcon', | ||
}; | ||
|
||
export const Default = () => ( | ||
<div style={{ padding: '3em' }}> | ||
<ClipboardIcon toCopy="value" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { color } from '../shared/styles'; | ||
import { Icon } from '../Icon'; | ||
import { Clipboard } from './Clipboard'; | ||
|
||
const StyledClipboard = styled(Clipboard)` | ||
line-height: 14px; | ||
padding: 5px; | ||
color: ${color.mediumdark}; | ||
&:hover { | ||
color: ${color.darker}; | ||
} | ||
`; | ||
|
||
interface StyledIconProps { | ||
copied: boolean; | ||
} | ||
|
||
const StyledIcon = styled(Icon)<StyledIconProps>` | ||
width: 14px; | ||
height: 14px; | ||
vertical-align: top; | ||
color: ${(props) => (props.copied ? color.positive : 'inherit')}; | ||
`; | ||
|
||
type ClipboardIconProps = Omit<React.ComponentPropsWithoutRef<typeof Clipboard>, 'children'>; | ||
|
||
export const ClipboardIcon = (props: ClipboardIconProps) => ( | ||
<StyledClipboard {...props}> | ||
{(copied) => <StyledIcon icon={copied ? 'check' : 'copy'} copied={copied} />} | ||
</StyledClipboard> | ||
); |
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,19 @@ | ||
import React from 'react'; | ||
|
||
import { ClipboardInput } from './ClipboardInput'; | ||
|
||
export default { | ||
title: 'Design System/Clipboard/ClipboardInput', | ||
}; | ||
|
||
export const Default = () => ( | ||
<div style={{ padding: '3em', width: 300 }}> | ||
<ClipboardInput label="Label" value="https://www.chromatic.com" /> | ||
</div> | ||
); | ||
|
||
export const Clipped = () => ( | ||
<div style={{ padding: '3em', width: 250 }}> | ||
<ClipboardInput label="Label" value="https://www.chromatic.com" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
// @ts-ignore | ||
import { Input } from '../Input'; | ||
import { color, spacing } from '../shared/styles'; | ||
import { ClipboardIcon } from './ClipboardIcon'; | ||
|
||
const Container = styled.div` | ||
position: relative; | ||
margin-top: 15px; | ||
`; | ||
|
||
const StyledInput = styled(Input)` | ||
width: 100%; | ||
display: block; | ||
&& input { | ||
padding-top: 7px !important; | ||
padding-bottom: 7px !important; | ||
padding-right: 26px !important; | ||
background: ${color.lightest}; | ||
border: 1px solid ${color.border}; | ||
border-radius: ${spacing.borderRadius.small}px; | ||
font-size: 11px; | ||
&:focus { | ||
box-shadow: none; | ||
border: 1px solid ${color.secondary}; | ||
} | ||
} | ||
`; | ||
|
||
const StyledClipboardIcon = styled(ClipboardIcon)` | ||
position: absolute; | ||
top: 4px; | ||
right: 4px; | ||
`; | ||
|
||
interface ClipboardInputProps extends React.ComponentPropsWithoutRef<typeof Input> { | ||
value: string; | ||
} | ||
|
||
export const ClipboardInput = ({ value, ...props }: ClipboardInputProps) => ( | ||
<Container> | ||
<StyledInput | ||
{...props} | ||
id="clipboard-input" | ||
icon={undefined} | ||
hideLabel | ||
value={value} | ||
appearance="code" | ||
readOnly | ||
/> | ||
<StyledClipboardIcon toCopy={value} /> | ||
</Container> | ||
); |
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