martmull
2024-11-13 14:32:40 +01:00
committed by GitHub
parent d2af97276d
commit ba79a1d324
8 changed files with 79 additions and 37 deletions

View File

@ -50,6 +50,7 @@ export * from './info/components/Info';
export * from './status/components/Status';
export * from './tag/components/Tag';
export * from './text/components/SeparatorLineText';
export * from './text/components/HorizontalSeparator';
export * from './tooltip/AppTooltip';
export * from './tooltip/OverflowingTextWithTooltip';
export * from './typography/components/H1Title';

View File

@ -0,0 +1,53 @@
import { JSX } from 'react';
import styled from '@emotion/styled';
type HorizontalSeparatorProps = {
visible?: boolean;
text?: string;
noMargin?: boolean;
};
const StyledSeparator = styled.div<HorizontalSeparatorProps>`
background-color: ${({ theme }) => theme.border.color.medium};
height: ${({ visible }) => (visible ? '1px' : 0)};
margin-bottom: ${({ theme, noMargin }) => (noMargin ? 0 : theme.spacing(3))};
margin-top: ${({ theme, noMargin }) => (noMargin ? 0 : theme.spacing(3))};
width: 100%;
`;
const StyledSeparatorContainer = styled.div<{ noMargin: boolean }>`
align-items: center;
display: flex;
margin-bottom: ${({ theme, noMargin }) => (noMargin ? 0 : theme.spacing(3))};
margin-top: ${({ theme, noMargin }) => (noMargin ? 0 : theme.spacing(3))};
width: 100%;
`;
const StyledLine = styled.div<HorizontalSeparatorProps>`
background-color: ${({ theme }) => theme.border.color.medium};
height: ${({ visible }) => (visible ? '1px' : 0)};
flex-grow: 1;
`;
const StyledText = styled.span`
color: ${({ theme }) => theme.font.color.light};
margin: 0 ${({ theme }) => theme.spacing(2)};
white-space: nowrap;
`;
export const HorizontalSeparator = ({
visible = true,
text = '',
noMargin = false,
}: HorizontalSeparatorProps): JSX.Element => (
<>
{text ? (
<StyledSeparatorContainer noMargin={noMargin}>
<StyledLine visible={visible} />
{text && <StyledText>{text}</StyledText>}
<StyledLine visible={visible} />
</StyledSeparatorContainer>
) : (
<StyledSeparator visible={visible} noMargin={noMargin} />
)}
</>
);

View File

@ -0,0 +1,15 @@
import { Meta, StoryObj } from '@storybook/react';
import { ComponentDecorator } from '@ui/testing';
import { HorizontalSeparator } from '../HorizontalSeparator';
const meta: Meta<typeof HorizontalSeparator> = {
title: 'UI/Display/Text/HorizontalSeparator',
component: HorizontalSeparator,
decorators: [ComponentDecorator],
};
export default meta;
type Story = StoryObj<typeof HorizontalSeparator>;
export const Default: Story = {};