Skip to content

Commit 24b2ac5

Browse files
JesmoDeviOvergaard
authored andcommitted
feat(uui-button): content align css variable (#548)
* button content alignment css prop * add story
1 parent f9fdbd2 commit 24b2ac5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/uui-button/lib/uui-button.element.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type UUIButtonType = 'submit' | 'button' | 'reset';
3939
* @cssprop --uui-button-contrast - overwrite the text color
4040
* @cssprop --uui-button-contrast-hover - overwrite the text color for hover state
4141
* @cssprop --uui-button-contrast-disabled - overwrite the text color for disabled state
42+
* @cssprop --uui-button-content-align - Overwrite justify-content alignment. Possible values: 'left', 'right', 'center'.
4243
*/
4344
@defineElement('uui-button')
4445
export class UUIButtonElement extends FormControlMixin(
@@ -110,7 +111,7 @@ export class UUIButtonElement extends FormControlMixin(
110111
111112
display: inline-flex;
112113
align-items: center;
113-
justify-content: center;
114+
justify-content: var(--uui-button-content-align, center);
114115
115116
/* for anchor tag: */
116117
text-decoration: none;

packages/uui-button/lib/uui-button.story.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export default {
5757
'--uui-button-contrast-hover': { control: { type: 'color' } },
5858
'--uui-button-background-color-disabled': { control: { type: 'color' } },
5959
'--uui-button-contrast-disabled': { control: { type: 'color' } },
60+
'--uui-button-content-align': {
61+
control: { type: 'select' },
62+
options: ['left', 'center', 'right'],
63+
},
6064
},
6165
parameters: {
6266
readme: {
@@ -79,6 +83,7 @@ const cssProps = [
7983
'--uui-button-contrast-hover',
8084
'--uui-button-background-color-disabled',
8185
'--uui-button-contrast-disabled',
86+
'--uui-button-content-align',
8287
];
8388

8489
const reducer = (prev: string, next: string, i: number) =>
@@ -428,3 +433,30 @@ export const MultiLine: Story = props => {
428433
};
429434

430435
MultiLine.args = { look: 'primary' };
436+
437+
export const ContentAlignment = props => html`
438+
<uui-button
439+
style="max-width: 400px; width: 100%;
440+
--uui-button-content-align: ${props['--uui-button-content-align']}"
441+
look="primary"
442+
color="danger"
443+
label="A11Y proper label">
444+
Content alignment
445+
</uui-button>
446+
`;
447+
ContentAlignment.args = { '--uui-button-content-align': 'left' };
448+
ContentAlignment.parameters = {
449+
controls: { include: ['--uui-button-content-align'] },
450+
docs: {
451+
source: {
452+
code: `
453+
<uui-button style="max-width: 400px; width: 100%; --uui-button-content-align: left}"
454+
look="primary"
455+
color="danger"
456+
label="A11Y proper label">
457+
Content alignment
458+
</uui-button>
459+
`,
460+
},
461+
},
462+
};

0 commit comments

Comments
 (0)