Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Jacouille/mantine
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacouille committed Oct 1, 2023
2 parents 0ccc852 + dd8e8e6 commit bbb68d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/mantine-core/src/components/Spoiler/Spoiler.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.root {
position: relative;

&[data-has-spoiler] {
margin-bottom: rem(24px);
margin-bottom: var(--spoiler-margin-bottom, rem(24px));
}
}

Expand Down
23 changes: 16 additions & 7 deletions src/mantine-core/src/components/Spoiler/Spoiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
createVarsResolver,
Factory,
rem,
getSpacing,
MantineSpacing,
} from '../../core';
import { Anchor } from '../Anchor';
import classes from './Spoiler.module.css';

export type SpoilerStylesNames = 'root' | 'control' | 'content';
export type SpoilerCssVariables = {
root: '--spoiler-transition-duration';
root: '--spoiler-transition-duration' | '--spoiler-margin-bottom';
};

export interface SpoilerProps
Expand All @@ -41,6 +43,9 @@ export interface SpoilerProps

/** Spoiler reveal transition duration in ms, set 0 or null to turn off animation, `200` by default */
transitionDuration?: number;

/** Margin bottom applied when the control button is shown, `rem(24px)` by default */
activeSpoilerMarginBottom?: MantineSpacing;
}

export type SpoilerFactory = Factory<{
Expand All @@ -55,12 +60,16 @@ const defaultProps: Partial<SpoilerProps> = {
initialState: false,
};

const varsResolver = createVarsResolver<SpoilerFactory>((_, { transitionDuration }) => ({
root: {
'--spoiler-transition-duration':
transitionDuration !== undefined ? `${transitionDuration}ms` : undefined,
},
}));
const varsResolver = createVarsResolver<SpoilerFactory>(
(_, { transitionDuration, activeSpoilerMarginBottom }) => ({
root: {
'--spoiler-transition-duration':
transitionDuration !== undefined ? `${transitionDuration}ms` : undefined,
'--spoiler-margin-bottom':
activeSpoilerMarginBottom !== undefined ? getSpacing(activeSpoilerMarginBottom) : undefined,
},
})
);

export const Spoiler = factory<SpoilerFactory>((_props, ref) => {
const props = useProps('Spoiler', defaultProps, _props);
Expand Down
4 changes: 3 additions & 1 deletion src/mantine-styles-api/src/data/Spoiler.styles-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ export const SpoilerStylesApi: StylesApiData<SpoilerFactory> = {
vars: {
root: {
'--spoiler-transition-duration': 'Controls transition duration',
'--spoiler-margin-bottom':
'Controls the margin bottom applied when the control button is shown',
},
},

modifiers: [
{
modifier: 'data-has-spoiler',
selector: 'root',
value: 'Whether the control button is shown or not',
condition: 'Whether the control button is shown or not',
},
],
};

0 comments on commit bbb68d6

Please sign in to comment.