Add spoiler UI component

This commit is contained in:
jeffvli 2024-02-01 03:58:36 -08:00
parent ea67a18962
commit 6aba41c3d9
3 changed files with 51 additions and 0 deletions

View file

@ -27,6 +27,7 @@ export * from './select';
export * from './skeleton'; export * from './skeleton';
export * from './slider'; export * from './slider';
export * from './spinner'; export * from './spinner';
export * from './spoiler';
export * from './switch'; export * from './switch';
export * from './tabs'; export * from './tabs';
export * from './text'; export * from './text';

View file

@ -0,0 +1,41 @@
import { ReactNode } from 'react';
import { Spoiler as MantineSpoiler } from '@mantine/core';
import { useTranslation } from 'react-i18next';
import styles from './spoiler.module.scss';
type SpoilerProps = {
children: ReactNode;
hideLabel?: boolean;
initialState?: boolean;
maxHeight: number;
showLabel?: ReactNode;
transitionDuration?: number;
};
export const Spoiler = ({
hideLabel,
initialState,
maxHeight,
showLabel,
transitionDuration,
children,
}: SpoilerProps) => {
const { t } = useTranslation();
return (
<MantineSpoiler
classNames={{
content: styles.content,
control: styles.control,
root: styles.root,
}}
hideLabel={hideLabel ?? t('common.collapse', { postProcess: 'sentenceCase' })}
initialState={initialState}
maxHeight={maxHeight ?? 75}
showLabel={showLabel ?? t('common.expand', { postProcess: 'sentenceCase' })}
transitionDuration={transitionDuration}
>
{children}
</MantineSpoiler>
);
};

View file

@ -0,0 +1,9 @@
.control {
color: var(--btn-subtle-fg);
font-weight: 600;
}
.control:hover {
color: var(--btn-subtle-fg-hover);
text-decoration: none;
}