Skip to content

Commit

Permalink
[@mantine/core] Button: Add loaderPosition="center" support (#2785)
Browse files Browse the repository at this point in the history
* [@mantine/core] Button: Add loaderPosition center option

* [docs] Update loaderPosition options
  • Loading branch information
odysseaspapadimas committed Oct 27, 2022
1 parent 42d1a3a commit 5f8c605
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/docs/core/Button.mdx
Expand Up @@ -50,7 +50,7 @@ button becomes disabled and white or dark overlay is added.
You can control loading state and [Loader](/core/loader/) component with following props:

- `loading` – enable loading state
- `loaderPosition` – Loader position relative to button label, either right or left
- `loaderPosition` – Loader position relative to button label, left, right or center
- `loaderProps` – props spread to Loader component, you can choose loader type, size and any other [supported](/core/loader/) prop

<Demo data={ButtonDemos.loadingConfigurator} />
Expand Down
7 changes: 7 additions & 0 deletions src/mantine-core/src/Button/Button.styles.ts
Expand Up @@ -181,6 +181,13 @@ export default createStyles(
marginLeft: 10,
},

centerLoader: {
position: 'absolute',
left: '50%',
transform: 'translateX(-50%)',
opacity: 0.5,
},

inner: {
display: 'flex',
alignItems: 'center',
Expand Down
6 changes: 5 additions & 1 deletion src/mantine-core/src/Button/Button.tsx
Expand Up @@ -57,7 +57,7 @@ export interface ButtonProps extends DefaultProps<ButtonStylesNames, ButtonStyle
loaderProps?: LoaderProps;

/** Loader position relative to button label */
loaderPosition?: 'left' | 'right';
loaderPosition?: 'left' | 'right' | 'center';

/** Button label */
children?: React.ReactNode;
Expand Down Expand Up @@ -142,6 +142,10 @@ export const _Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) =
</span>
)}

{loading && loaderPosition === 'center' && (
<span className={classes.centerLoader}>{loader}</span>
)}

<span
className={classes.label}
style={{ textTransform: uppercase ? 'uppercase' : undefined }}
Expand Down
Expand Up @@ -39,6 +39,7 @@ export const loadingConfigurator: MantineDemo = {
data: [
{ label: 'Left', value: 'left' },
{ label: 'Right', value: 'right' },
{ label: 'Center', value: 'center' },
],
initialValue: 'left',
defaultValue: 'left',
Expand Down
1 change: 1 addition & 0 deletions src/mantine-styles-api/src/styles-api/Button.styles-api.ts
Expand Up @@ -5,6 +5,7 @@ export const Button: Record<ButtonStylesNames, string> = {
icon: 'Shared icon styles',
leftIcon: 'Left icon',
rightIcon: 'Right icon',
centerLoader: 'Center loader',
inner: 'Contains label, left and right icons',
label: 'Contains button children',
};

0 comments on commit 5f8c605

Please sign in to comment.