diff --git a/packages/grafana-ui/src/components/Divider/Divider.mdx b/packages/grafana-ui/src/components/Divider/Divider.mdx
index 82269111f0a..1c9d9784273 100644
--- a/packages/grafana-ui/src/components/Divider/Divider.mdx
+++ b/packages/grafana-ui/src/components/Divider/Divider.mdx
@@ -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';
+
+
+ My title here
+
+
+
+
+ Main content goes here
+
+
+```
+
### Dos
- Import and add the Divider component inside the code where you would normally add an hr or a div.
diff --git a/packages/grafana-ui/src/components/Divider/Divider.story.tsx b/packages/grafana-ui/src/components/Divider/Divider.story.tsx
index d6adb758de5..9a0ffcd10a5 100644
--- a/packages/grafana-ui/src/components/Divider/Divider.story.tsx
+++ b/packages/grafana-ui/src/components/Divider/Divider.story.tsx
@@ -17,8 +17,14 @@ const meta: Meta = {
},
};
-export const Basic: StoryFn = ({ direction }) => {
- return ;
+export const Basic: StoryFn = ({ direction, spacing }) => {
+ return (
+
+
My text here
+
+
My text here
+
+ );
};
export const Examples: StoryFn = () => {
diff --git a/packages/grafana-ui/src/components/Divider/Divider.tsx b/packages/grafana-ui/src/components/Divider/Divider.tsx
index 8d2f2fc5644..f7656374d4f 100644
--- a/packages/grafana-ui/src/components/Divider/Divider.tsx
+++ b/packages/grafana-ui/src/components/Divider/Divider.tsx
@@ -1,17 +1,17 @@
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 {
direction?: 'vertical' | 'horizontal';
+ spacing?: ThemeSpacingTokens;
}
-export const Divider = ({ direction = 'horizontal' }: DividerProps) => {
- const theme = useTheme2();
- const styles = getStyles(theme);
+export const Divider = ({ direction = 'horizontal', spacing = 2 }: DividerProps) => {
+ const styles = useStyles2(useCallback((theme) => getStyles(theme, spacing), [spacing]));
if (direction === 'vertical') {
return ;
@@ -22,16 +22,16 @@ export const Divider = ({ direction = 'horizontal' }: DividerProps) => {
Divider.displayName = 'Divider';
-const getStyles = (theme: GrafanaTheme2) => {
+const getStyles = (theme: GrafanaTheme2, spacing: ThemeSpacingTokens) => {
return {
horizontalDivider: css({
borderTop: `1px solid ${theme.colors.border.weak}`,
- margin: theme.spacing(2, 0),
+ margin: theme.spacing(spacing, 0),
width: '100%',
}),
verticalDivider: css({
borderRight: `1px solid ${theme.colors.border.weak}`,
- margin: theme.spacing(0, 0.5),
+ margin: theme.spacing(0, spacing),
height: '100%',
}),
};