3
0
mirror of https://github.com/grafana/grafana.git synced 2025-02-25 18:55:37 -06:00

GrafanaUI: Added spacing token to Divider Component ()

* GrafanaUI: Added spacing token to Divider Component

* Made changes suggested
This commit is contained in:
RoxanaAnamariaTurc 2023-08-02 14:18:06 +03:00 committed by GitHub
parent 8a24e891fe
commit f59117057e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 11 deletions
packages/grafana-ui/src/components/Divider

View File

@ -52,6 +52,24 @@ import { Divider } from '@grafana/ui';
``` ```
### Modifiers
Pass a spacing token into the `spacing` prop to adjust the margin.
```tsx
import { Divider } from '@grafana/ui';
<header>
<h1>My title here</h1>
<Divider direction="vertical" spacing={0.5}/>
<img src="logo.png" alt="logo" />
</header>
<main>
<p>Main content goes here</p>
</main>
```
### Dos ### Dos
- Import and add the Divider component inside the code where you would normally add an hr or a div. - Import and add the Divider component inside the code where you would normally add an hr or a div.

View File

@ -17,8 +17,14 @@ const meta: Meta<typeof Divider> = {
}, },
}; };
export const Basic: StoryFn<typeof Divider> = ({ direction }) => { export const Basic: StoryFn<typeof Divider> = ({ direction, spacing }) => {
return <Divider direction={direction} />; return (
<div style={{ display: direction === 'vertical' ? 'flex' : 'block', flexDirection: 'row', height: '50px' }}>
<div>My text here</div>
<Divider direction={direction} spacing={spacing} />
<div>My text here</div>
</div>
);
}; };
export const Examples: StoryFn<typeof Divider> = () => { export const Examples: StoryFn<typeof Divider> = () => {

View File

@ -1,17 +1,17 @@
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import React from 'react'; import React, { useCallback } from 'react';
import { GrafanaTheme2 } from '@grafana/data'; import { GrafanaTheme2, ThemeSpacingTokens } from '@grafana/data';
import { useTheme2 } from '../../themes'; import { useStyles2 } from '../../themes';
interface DividerProps { interface DividerProps {
direction?: 'vertical' | 'horizontal'; direction?: 'vertical' | 'horizontal';
spacing?: ThemeSpacingTokens;
} }
export const Divider = ({ direction = 'horizontal' }: DividerProps) => { export const Divider = ({ direction = 'horizontal', spacing = 2 }: DividerProps) => {
const theme = useTheme2(); const styles = useStyles2(useCallback((theme) => getStyles(theme, spacing), [spacing]));
const styles = getStyles(theme);
if (direction === 'vertical') { if (direction === 'vertical') {
return <div className={styles.verticalDivider}></div>; return <div className={styles.verticalDivider}></div>;
@ -22,16 +22,16 @@ export const Divider = ({ direction = 'horizontal' }: DividerProps) => {
Divider.displayName = 'Divider'; Divider.displayName = 'Divider';
const getStyles = (theme: GrafanaTheme2) => { const getStyles = (theme: GrafanaTheme2, spacing: ThemeSpacingTokens) => {
return { return {
horizontalDivider: css({ horizontalDivider: css({
borderTop: `1px solid ${theme.colors.border.weak}`, borderTop: `1px solid ${theme.colors.border.weak}`,
margin: theme.spacing(2, 0), margin: theme.spacing(spacing, 0),
width: '100%', width: '100%',
}), }),
verticalDivider: css({ verticalDivider: css({
borderRight: `1px solid ${theme.colors.border.weak}`, borderRight: `1px solid ${theme.colors.border.weak}`,
margin: theme.spacing(0, 0.5), margin: theme.spacing(0, spacing),
height: '100%', height: '100%',
}), }),
}; };