Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button loader position center #2785

Merged
merged 2 commits into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
};