Skip to content

Commit

Permalink
fix(ui-library): props alignment form caption
Browse files Browse the repository at this point in the history
  • Loading branch information
RubirajAccenture committed Mar 15, 2024
1 parent 9363f94 commit c13d86a
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 37 deletions.
4 changes: 2 additions & 2 deletions packages/ui-library/src/components/checkbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class BlrCheckbox extends LitElement {
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.hintMessage,
icon: this.hintIcon,
})}
Expand All @@ -211,7 +211,7 @@ export class BlrCheckbox extends LitElement {
${BlrFormCaptionRenderFunction({
variant: 'error',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.errorMessage,
icon: this.errorIcon,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ It is not intended to use the Form Caption Group directly when creating new appl
const hintCaption = BlrFormCaptionRenderFunction({
message: 'hint',
variant: 'hint',
showIcon: true,
icon: 'blrInfo',
theme: 'Light',
});

const errorCaption = BlrFormCaptionRenderFunction({
message: 'error',
variant: 'error',
showIcon: true,
icon: 'blrErrorFilled',
theme: 'Light',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ const sampleParams: BlrFormCaptionGroupType = {
const hintCaption = BlrFormCaptionRenderFunction({
message: 'This is a hint',
variant: 'hint',
showIcon: true,
icon: 'blrInfo',
size: 'md',
sizeVariant: 'md',
theme: 'Light',
});

const errorCaption = BlrFormCaptionRenderFunction({
message: 'This is an error',
variant: 'error',
showIcon: true,
icon: 'blrInfo',
size: 'md',
sizeVariant: 'md',
theme: 'Light',
});

Expand Down
40 changes: 27 additions & 13 deletions packages/ui-library/src/components/form-caption/index.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const sharedStyles = html`
export default {
title: 'Components/Form Caption',
argTypes: {
size: {
sizeVariant: {
options: FormSizes,
control: { type: 'radio' },
defaultValue: 'sm',
description: ' Choose size of the component.',
table: {
category: 'Appearance',
Expand All @@ -44,12 +45,20 @@ export default {
},
},

showIcon: {
description: 'Choose if component has an icon.',
defaultValue: true,
control: { type: 'boolean' },
table: { category: 'Content / Settings' },
},

icon: {
options: [undefined, ...PureIconKeys],
control: { type: 'select' },
defaultValue: 'blr360',
description: 'Select an icon which is displayed inside of the input.',
table: {
category: 'Content / Setting',
category: 'Content / Settings',
},
},
message: {
Expand All @@ -72,15 +81,12 @@ export default {
description: {
component: `<Markdown>
Form Caption provides either a brief hint or error message to a related form element such as Input Field Text or Select. It is typically displayed below the form element, and it can be used to provide additional information about the type of information a user has to provide, like an example of the correct data format.
- [**Appearance**](#appearance)
- [**Variant**](#variant)
- [**Size Variant**](#size-variant)
- [**Dependencies**](#dependencies)
- [**Icon**](#icon)
The Form Caption is intended to be used when creating new components. Currently, it is used like this in the following components:
- [**Form Caption Group**](?path=/docs/components-form-caption-group--docs)
- [**Toggle Switch**](?path=/docs/components-toggle-switch--docs)
Expand All @@ -99,9 +105,10 @@ BlrFormCaption.storyName = 'Form Caption';
const args: BlrFormCaptionType = {
theme: 'Light',
message: 'Message-text',
showIcon: true,
icon: 'blr360',
variant: 'hint',
size: 'sm',
sizeVariant: 'sm',
};

BlrFormCaption.args = args;
Expand All @@ -119,17 +126,19 @@ export const Variant = () => {
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: 'Light',
size: 'sm',
sizeVariant: 'sm',
message: 'Hint',
showIcon: true,
icon: 'blr360',
})}
</div>
<div class="wrapper">
${BlrFormCaptionRenderFunction({
variant: 'error',
theme: 'Light',
size: 'sm',
sizeVariant: 'sm',
message: 'Error',
showIcon: true,
icon: 'blrErrorFilled',
})}
</div>
Expand All @@ -149,17 +158,19 @@ export const SizeVariant = () => {
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: 'Light',
size: 'sm',
sizeVariant: 'sm',
message: 'Form Caption SM',
showIcon: true,
icon: 'blr360',
})}
</div>
<div class="wrapper">
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: 'Light',
size: 'md',
sizeVariant: 'md',
message: 'Form Caption MD',
showIcon: true,
icon: 'blr360',
})}
</div>
Expand All @@ -168,8 +179,9 @@ export const SizeVariant = () => {
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: 'Light',
size: 'lg',
sizeVariant: 'lg',
message: 'Form Caption LG',
showIcon: true,
icon: 'blr360',
})}
</div>
Expand All @@ -191,17 +203,19 @@ export const Icon = () => {
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: 'Light',
size: 'sm',
sizeVariant: 'sm',
message: 'With icon',
showIcon: true,
icon: 'blr360',
})}
</div>
<div class="wrapper">
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: 'Light',
size: 'sm',
sizeVariant: 'sm',
message: 'Without icon',
showIcon: false,
})}
</div>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { querySelectorDeep } from 'query-selector-shadow-dom';
const sampleParams: BlrFormCaptionType = {
theme: 'Light',
message: 'hallo',
showIcon: true,
icon: 'blr360',
variant: 'hint',
size: 'sm',
sizeVariant: 'sm',
};

describe('blr-form-caption', () => {
Expand Down
13 changes: 7 additions & 6 deletions packages/ui-library/src/components/form-caption/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,42 @@ export class BlrFormCaption extends LitElement {
static styles = [];

@property() message?: string;
@property({ type: Boolean }) showIcon: boolean = true;
@property() icon?: SizelessIconType;
@property() variant: CaptionVariantType = 'hint';
@property() size?: FormSizesType = 'md';
@property() sizeVariant?: FormSizesType = 'md';
@property() childElement?: TemplateResult<1>;
@property() theme: ThemeType = 'Light';

protected render() {
if (this.size) {
if (this.sizeVariant) {
const dynamicStyles = this.theme === 'Light' ? [captionLight] : [captionDark];

const classes = classMap({
'blr-form-caption': true,
[`${this.variant}`]: this.variant,
[`${this.size}`]: this.size,
[`${this.sizeVariant}`]: this.sizeVariant,
});

const iconClasses = classMap({
'blr-icon': true,
[this.size]: this.size,
[this.sizeVariant]: this.sizeVariant,
});

const iconSizeVariant = getComponentConfigToken([
'cmp',
'CaptionComponent',
'Icon',
'SizeVariant',
this.size.toUpperCase(),
this.sizeVariant.toUpperCase(),
]).toLowerCase() as SizesType;

return html`
<style>
${dynamicStyles}
</style>
<div class=${classes}>
${this.icon
${this.showIcon
? BlrIconRenderFunction(
{
icon: calculateIconName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ export class BlrInputFieldNumber extends LitElement {
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: this.theme,
size: this.sizeVariant,
sizeVariant: this.sizeVariant,
message: this.hintMessage,
showIcon: Boolean(this.hintIcon),
icon: this.hintIcon,
})}
</div>
Expand All @@ -288,8 +289,9 @@ export class BlrInputFieldNumber extends LitElement {
${BlrFormCaptionRenderFunction({
variant: 'error',
theme: this.theme,
size: this.sizeVariant,
sizeVariant: this.sizeVariant,
message: this.errorMessage,
showIcon: Boolean(this.errorIcon),
icon: this.errorIcon,
})}
</div>
Expand Down
6 changes: 4 additions & 2 deletions packages/ui-library/src/components/input-field-text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,19 @@ export class BlrInputFieldText extends LitElement {
? BlrFormCaptionRenderFunction({
variant: 'hint',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.hintMessage,
showIcon: Boolean(this.hintIcon),
icon: this.hintIcon,
})
: nothing}
${this.hasError && (this.errorMessage || this.errorIcon)
? BlrFormCaptionRenderFunction({
variant: 'error',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.errorMessage,
showIcon: Boolean(this.errorIcon),
icon: this.errorIcon,
})
: nothing}
Expand Down
6 changes: 4 additions & 2 deletions packages/ui-library/src/components/radio-group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ export class BlrRadioGroup extends LitElement {
? BlrFormCaptionRenderFunction({
variant: 'hint',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.groupHintMessage,
showIcon: Boolean(this.groupHintIcon),
icon: this.groupHintIcon,
})
: nothing}
${this.hasError && (this.groupErrorMessage || this.groupErrorIcon)
? BlrFormCaptionRenderFunction({
variant: 'error',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.groupErrorMessage,
showIcon: Boolean(this.groupErrorIcon),
icon: this.groupErrorIcon,
})
: nothing}
Expand Down
6 changes: 4 additions & 2 deletions packages/ui-library/src/components/radio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ export class BlrRadio extends LitElement {
${BlrFormCaptionRenderFunction({
variant: 'hint',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.hintMessage,
showIcon: Boolean(this.hintIcon),
icon: this.hintIcon,
})}
</div>
Expand All @@ -67,8 +68,9 @@ export class BlrRadio extends LitElement {
${BlrFormCaptionRenderFunction({
variant: 'error',
theme: this.theme,
size: this.size,
sizeVariant: this.size,
message: this.errorMessage,
showIcon: Boolean(this.errorIcon),
icon: this.errorIcon,
})}
</div>
Expand Down
6 changes: 4 additions & 2 deletions packages/ui-library/src/components/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ export class BlrSelect extends LitElement {
? BlrFormCaptionRenderFunction({
variant: 'hint',
theme: this.theme,
size: this.sizeVariant,
sizeVariant: this.sizeVariant,
message: this.hintMessage,
showIcon: Boolean(this.hintMessageIcon),
icon: this.hintMessageIcon,
})
: nothing}
${this.hasError && (this.errorMessage || this.errorMessageIcon)
? BlrFormCaptionRenderFunction({
variant: 'error',
theme: this.theme,
size: this.sizeVariant,
sizeVariant: this.sizeVariant,
message: this.errorMessage,
showIcon: Boolean(this.errorMessageIcon),
icon: this.errorMessageIcon,
})
: nothing}
Expand Down
6 changes: 4 additions & 2 deletions packages/ui-library/src/components/textarea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,19 @@ export class BlrTextarea extends LitElement {
? BlrFormCaptionRenderFunction({
variant: 'hint',
theme: this.theme,
size: this.sizeVariant,
sizeVariant: this.sizeVariant,
message: this.hintMessage,
showIcon: Boolean(this.hintMessageIcon),
icon: this.hintMessageIcon,
})
: nothing}
${this.hasError && (this.errorMessage || this.errorMessageIcon)
? BlrFormCaptionRenderFunction({
variant: 'error',
theme: this.theme,
size: this.sizeVariant,
sizeVariant: this.sizeVariant,
message: this.errorMessage,
showIcon: Boolean(this.errorMessageIcon),
icon: this.errorMessageIcon,
})
: nothing}
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-library/src/components/toggle-switch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ export class BlrToggleSwitch extends LitElement {
? BlrFormCaptionRenderFunction({
message: this.hintMessage,
variant: 'hint',
showIcon: Boolean(this.hintIcon),
icon: this.hintIcon,
size: this.size || 'sm',
sizeVariant: this.size || 'sm',
theme: this.theme,
})
: nothing}
Expand Down

0 comments on commit c13d86a

Please sign in to comment.