Skip to content

Commit

Permalink
feat: add HoverBox component
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Aug 29, 2020
1 parent 449617e commit c546119
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 24 deletions.
29 changes: 5 additions & 24 deletions plugins/viewport-plugin/src/ViewportBlock/ViewportBox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @jsx jsx */
import { FC } from 'react';
import { Box, Theme, Text, jsx } from 'theme-ui';
import React, { FC } from 'react';
import { Story } from '@component-controls/blocks';
import { HoverBox } from '@component-controls/components';

export interface ViewportBoxProps {
storyId?: string;
Expand All @@ -14,26 +13,8 @@ export const ViewportBox: FC<ViewportBoxProps> = ({
sizeLabel,
}) => {
return (
<Box
sx={{
minHeight: '100%',
minWidth: 'unset',
pr: 4,
':hover': {
'& > div': {
color: 'mutedText',
},
},
}}
>
<Box
sx={{
boxShadow: (t: Theme) => `0px 2px 6px 0px ${t.colors?.shadow}`,
}}
>
<Story id={storyId} sxStyle={{ mb: 0, minWidth: size }} />
</Box>
<Text sx={{ color: 'muted', fontWeight: 'bold' }}>{sizeLabel}</Text>
</Box>
<HoverBox label={sizeLabel}>
<Story id={storyId} sxStyle={{ mb: 0, minWidth: size }} />
</HoverBox>
);
};
13 changes: 13 additions & 0 deletions ui/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [<ins>ColorMode</ins>](#inscolormodeins)
- [<ins>ExternalLink</ins>](#insexternallinkins)
- [<ins>Header</ins>](#insheaderins)
- [<ins>HoverBox</ins>](#inshoverboxins)
- [<ins>Keyboard</ins>](#inskeyboardins)
- [<ins>Link</ins>](#inslinkins)
- [<ins>LinkContextProvider</ins>](#inslinkcontextproviderins)
Expand Down Expand Up @@ -192,6 +193,18 @@ _Header [source code](https://github.com/ccontrols/component-controls/tree/maste
| `as` | _ElementType&lt;any>_ | |
| `variant` | _string_ | |

## <ins>HoverBox</ins>

Box component that will fade/outline a label at the bottom

_HoverBox [source code](https://github.com/ccontrols/component-controls/tree/master/ui/components/src/HoverBox/HoverBox.tsx)_

### properties

| Name | Type | Description |
| -------- | -------- | ---------------------------------------------- |
| `label*` | _string_ | laabel to be displayed when the box is hovered |

## <ins>Keyboard</ins>

Componet to monitor keystrokes. Can attach to child, document or window.
Expand Down
14 changes: 14 additions & 0 deletions ui/components/src/HoverBox/HoverBox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { Donut } from 'theme-ui';
import { HoverBox } from '.';

export default {
title: 'Components/HoverBox',
component: HoverBox,
};

export const overview = () => (
<HoverBox label="donut component">
<Donut value={1 / 2} />,
</HoverBox>
);
23 changes: 23 additions & 0 deletions ui/components/src/HoverBox/HoverBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Box, Text } from 'theme-ui';

export interface HoverBoxProps {
/**
* laabel to be displayed when the box is hovered
*/
label: string;
}

/**
* Box component that will fade/outline a label at the bottom
*
*/
export const HoverBox: FC<HoverBoxProps> = ({ label, children }) => {
return (
<Box variant="hoverbox.container">
<Box variant="hoverbox.inner">{children}</Box>
<Text variant="hoverbox.text">{label}</Text>
</Box>
);
};
1 change: 1 addition & 0 deletions ui/components/src/HoverBox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './HoverBox';
17 changes: 17 additions & 0 deletions ui/components/src/ThemeContext/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type ControlsTheme = {
story: Record<string, ThemeUIStyleObject>;
colormode: Record<string, ThemeUIStyleObject>;
header: ThemeUIStyleObject;
hoverbox: Record<string, ThemeUIStyleObject>;
navmenu: Record<string, ThemeUIStyleObject>;
pagination: Record<string, ThemeUIStyleObject>;
sidebar: Record<string, ThemeUIStyleObject>;
Expand Down Expand Up @@ -735,6 +736,22 @@ export const theme: ControlsTheme = {
alignItems: 'center',
boxShadow: (t: Theme) => `0 1px 3px 1px ${t.colors?.shadow}`,
},
hoverbox: {
container: {
minHeight: '100%',
minWidth: 'unset',
pr: 4,
':hover': {
'& > div': {
color: 'mutedText',
},
},
},
inner: {
boxShadow: (t: Theme) => `0px 2px 6px 0px ${t.colors?.shadow}`,
},
text: { color: 'muted', fontWeight: 'bold' },
},
navmenu: {
link: {
width: '100%',
Expand Down
1 change: 1 addition & 0 deletions ui/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './Collapsible';
export * from './ColorMode';
export * from './ExternalLink';
export * from './Header';
export * from './HoverBox';
export * from './Keyboard';
export * from './Link';
export * from './Markdown';
Expand Down

0 comments on commit c546119

Please sign in to comment.