-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fce8433
commit 6e4fbcc
Showing
5 changed files
with
97 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { Document, Example } from '@component-controls/core'; | ||
import { ThemeProvider } from '../ThemeContext'; | ||
import { InfoTip, InfoTipProps } from './InfoTip'; | ||
|
||
export default { | ||
title: 'Components/InfoTip', | ||
component: InfoTip, | ||
category: 'Display', | ||
} as Document; | ||
|
||
export const overview: Example<InfoTipProps> = ({ children, size }) => ( | ||
<ThemeProvider> | ||
<InfoTip size={size}>{children}</InfoTip> | ||
</ThemeProvider> | ||
); | ||
|
||
overview.controls = { | ||
children: ` | ||
# Header H1 | ||
## Header H2 | ||
### Header H3 | ||
#### Header H4 | ||
##### Header H5 | ||
some text | ||
`, | ||
size: 18, | ||
}; |
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,51 @@ | ||
/** @jsx jsx */ | ||
import { FC, ReactNode } from 'react'; | ||
import { jsx, Button, Box } from 'theme-ui'; | ||
import { InfoIcon } from '@primer/octicons-react'; | ||
import { Popover, PopoverProps } from '../Popover'; | ||
import { Markdown } from '../Markdown'; | ||
|
||
export interface InfoTipProps { | ||
/** | ||
* size of the icon in pixels | ||
*/ | ||
size?: number; | ||
|
||
/** | ||
* custom ico | ||
*/ | ||
icon?: ReactNode; | ||
} | ||
|
||
/** | ||
* | ||
* Displays a value with a small label | ||
*/ | ||
export const InfoTip: FC<InfoTipProps & PopoverProps> = ({ | ||
size = 18, | ||
icon, | ||
children, | ||
...rest | ||
}) => { | ||
const iconNode = icon || <InfoIcon size={size} />; | ||
return ( | ||
<Popover | ||
trigger="hover" | ||
placement="bottom-start" | ||
tooltip={() => ( | ||
<Box variant="infotip.container"> | ||
{typeof children === 'string' ? ( | ||
<Markdown>{children}</Markdown> | ||
) : ( | ||
children | ||
)} | ||
</Box> | ||
)} | ||
{...rest} | ||
> | ||
<Button variant="plain" sx={{ mx: 2 }}> | ||
{iconNode} | ||
</Button> | ||
</Popover> | ||
); | ||
}; |
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 @@ | ||
export * from './InfoTip'; |
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