-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui-library): forms with&without slot and simple manual validation(…
- Loading branch information
1 parent
c0de271
commit e84fe8d
Showing
15 changed files
with
767 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/ui-library/src/components/form-example-with-slot/index.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { typeSafeNestedCss as css } from "../../utils/nested-typesafe-css-literals"; | ||
import { renderThemedCssStrings } from "../../foundation/_tokens-generated/index.pseudo.generated"; | ||
|
||
export const { tokenizedLight: captionLight, tokenizedDark: captionDark } = renderThemedCssStrings((componentTokens) => { | ||
const { CaptionComponent } = componentTokens.Forms; | ||
|
||
return css` | ||
.blr-form-caption { | ||
width: 100%; | ||
display: flex; | ||
align-items: flex-start; | ||
color: ${CaptionComponent.Text.TextColor.Hint}; | ||
&.error { | ||
color: ${CaptionComponent.Text.TextColor.Error}; | ||
} | ||
&.sm { | ||
padding: ${CaptionComponent.Container.Padding.SM}; | ||
gap: ${CaptionComponent.Container.ItemSpacing.SM}; | ||
.blr-icon { | ||
padding-top: ${CaptionComponent.IconWrapper.PaddingTop.SM}; | ||
height: ${CaptionComponent.Icon.IconSize.SM}; | ||
width: ${CaptionComponent.Icon.IconSize.SM}; | ||
} | ||
.blr-caption-text { | ||
padding: ${CaptionComponent.TextWrapper.Padding.SM}; | ||
font-family: ${CaptionComponent.Text.Typography.SM.fontFamily}, sans-serif; | ||
font-weight: ${CaptionComponent.Text.Typography.SM.fontWeight}; | ||
font-size: ${CaptionComponent.Text.Typography.SM.fontSize}; | ||
line-height: ${CaptionComponent.Text.Typography.SM.lineHeight}; | ||
} | ||
} | ||
&.md { | ||
padding: ${CaptionComponent.Container.Padding.MD}; | ||
gap: ${CaptionComponent.Container.ItemSpacing.MD}; | ||
.blr-icon { | ||
padding-top: ${CaptionComponent.IconWrapper.PaddingTop.MD}; | ||
height: ${CaptionComponent.Icon.IconSize.MD}; | ||
width: ${CaptionComponent.Icon.IconSize.MD}; | ||
} | ||
.blr-caption-text { | ||
padding: ${CaptionComponent.TextWrapper.Padding.MD}; | ||
font-family: ${CaptionComponent.Text.Typography.MD.fontFamily}, sans-serif; | ||
font-weight: ${CaptionComponent.Text.Typography.MD.fontWeight}; | ||
font-size: ${CaptionComponent.Text.Typography.MD.fontSize}; | ||
line-height: ${CaptionComponent.Text.Typography.MD.lineHeight}; | ||
} | ||
} | ||
&.lg { | ||
padding: ${CaptionComponent.Container.Padding.LG}; | ||
gap: ${CaptionComponent.Container.ItemSpacing.LG}; | ||
.blr-icon { | ||
padding-top: ${CaptionComponent.IconWrapper.PaddingTop.LG}; | ||
height: ${CaptionComponent.Icon.IconSize.LG}; | ||
width: ${CaptionComponent.Icon.IconSize.LG}; | ||
} | ||
.blr-caption-text { | ||
padding: ${CaptionComponent.TextWrapper.Padding.LG}; | ||
font-family: ${CaptionComponent.Text.Typography.LG.fontFamily}, sans-serif; | ||
font-weight: ${CaptionComponent.Text.Typography.LG.fontWeight}; | ||
font-size: ${CaptionComponent.Text.Typography.LG.fontSize}; | ||
line-height: ${CaptionComponent.Text.Typography.LG.lineHeight}; | ||
} | ||
} | ||
} | ||
`; | ||
}); |
50 changes: 50 additions & 0 deletions
50
packages/ui-library/src/components/form-example-with-slot/index.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable no-console */ | ||
import { PureIconKeys } from '@boiler/icons'; | ||
import { FormSizes, CaptionVariants } from '../../globals/constants'; | ||
Check failure on line 3 in packages/ui-library/src/components/form-example-with-slot/index.stories.ts GitHub Actions / eslint
|
||
import { BlrFormExampleWithSlotType } from './index'; | ||
import { BlrFormExampleWithSlotRenderFunction } from './renderFunction'; | ||
import { Themes } from '../../foundation/_tokens-generated/index.themes'; | ||
import { html } from 'lit-html'; | ||
import '../../index'; | ||
|
||
const sharedStyles = html` | ||
<style> | ||
.wrapper { | ||
padding: 1.25em; | ||
background: red; | ||
} | ||
</style> | ||
`; | ||
|
||
export default { | ||
title: 'Components/Form Example', | ||
argTypes: {}, | ||
parameters: { | ||
badges: ['Draft'], | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/C4vgEKz8mKyulJ4gm3Qdql/%F0%9F%AB%A7-%5BBLR%5D-The-B01LER?node-id=3618%3A125223&mode=dev', | ||
}, | ||
viewMode: 'docs', | ||
layout: 'centered', | ||
docs: { | ||
description: { | ||
component: `<Markdown> | ||
This is experimental form. | ||
</Markdown> | ||
`, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const BlrFormExampleWithSlot = (params: BlrFormExampleWithSlotType) => | ||
BlrFormExampleWithSlotRenderFunction(params); | ||
|
||
BlrFormExampleWithSlot.storyName = 'BlrFormExampleWithSlot'; | ||
|
||
const args: BlrFormExampleWithSlotType = { | ||
theme: 'Light', | ||
}; | ||
|
||
BlrFormExampleWithSlot.args = args; |
144 changes: 144 additions & 0 deletions
144
packages/ui-library/src/components/form-example-with-slot/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { LitElement, html } from 'lit'; | ||
import { TAG_NAME } from './renderFunction'; | ||
import { ThemeType } from '../../foundation/_tokens-generated/index.themes'; | ||
import { property } from 'lit/decorators.js'; | ||
|
||
export class BlrFormExampleWithSlot extends LitElement { | ||
@property() theme: ThemeType = 'Light'; | ||
@property() firstInputValue: string = ''; | ||
@property() secondInputValue: string = ''; | ||
@property({ reflect: true }) checkBoxChecked: boolean = false; | ||
|
||
protected render() { | ||
return html` | ||
<blr-form .handleSubmit="${this.handleSubmit}"> | ||
<blr-text-input | ||
size="md" | ||
placeholder="Placeholder-text" | ||
value="${this.firstInputValue}" | ||
maxlength="140" | ||
label="Label-text" | ||
labelappendix="(Appendix)" | ||
arialabel="firstInput" | ||
name="firstInput" | ||
theme="Light" | ||
textinputid="firstInput" | ||
haslabel="true" | ||
type="text" | ||
inputicon="blr360" | ||
showinputicon="true" | ||
@blrTextValueChange="${this.handleFirstInputChange}" | ||
required="true" | ||
></blr-text-input> | ||
<blr-text-input | ||
size="md" | ||
placeholder="Placeholder-text" | ||
value="${this.secondInputValue}" | ||
maxlength="140" | ||
label="Label-text" | ||
labelappendix="(Appendix)" | ||
arialabel="secondInput" | ||
name="secondInput" | ||
theme="Light" | ||
textinputid="secondInput" | ||
haslabel="true" | ||
type="text" | ||
inputicon="blr360" | ||
showinputicon="true" | ||
@blrTextValueChange="${this.handleSecondInputChange}" | ||
required="true" | ||
></blr-text-input> | ||
<blr-checkbox | ||
theme="Light" | ||
size="md" | ||
checkedicon="blrCheckmark" | ||
indeterminatedicon="blrMinus" | ||
haslabel="true" | ||
label="I accept the terms and conditions." | ||
hintmessage="This is a small hint message" | ||
hinticon="blrInfo" | ||
erroricon="" | ||
arialabel="check Input" | ||
checkinputid="checkInputId" | ||
name="checkInput" | ||
@blrCheckedChange=${this.handleCheckInput} | ||
?checked=${this.checkBoxChecked} | ||
></blr-checkbox> | ||
</blr-form> | ||
`; | ||
} | ||
|
||
private handleSubmit(e) { | ||
const slot = this.renderRoot?.querySelector('slot'); | ||
const assignedNodes = slot?.assignedElements({ flatten: true }) ?? []; | ||
assignedNodes.forEach((node: any) => { | ||
if (node.name === 'firstInput') { | ||
if (node.hasAttribute('required') && node.value === '') { | ||
node._onPropChanged({ | ||
detail: { | ||
hasError: true, | ||
errorMessage: 'This is a required field', | ||
}, | ||
}); | ||
} else { | ||
this.firstInputValue = node.value; | ||
} | ||
} | ||
|
||
if (node.name === 'secondInput') { | ||
if (node.hasAttribute('required') && node.value === '') { | ||
node._onPropChanged({ | ||
detail: { | ||
hasError: true, | ||
errorMessage: 'This is a second required field', | ||
}, | ||
}); | ||
} else { | ||
this.secondInputValue = node.value; | ||
} | ||
} | ||
|
||
if (node.name === 'checkInput' && !node.hasAttribute('checked')) { | ||
node._onPropChanged({ | ||
detail: { | ||
hasError: true, | ||
errorMessage: 'Error: Unchecked', | ||
}, | ||
}); | ||
} | ||
}); | ||
|
||
// just to simulate the value change. Remove later | ||
setTimeout(() => { | ||
this.dispatchEvent( | ||
new CustomEvent('propChanged', { | ||
detail: { hasError: false, errorMessage: '' }, | ||
bubbles: true, | ||
composed: true, | ||
}) | ||
); | ||
}, 3000); | ||
|
||
console.log( | ||
`The submitted value are firstName: ${this.firstInputValue} lastName: ${this.secondInputValue} and TOA checked is ${this.checkBoxChecked}` | ||
); | ||
} | ||
|
||
private handleFirstInputChange(evt: any) { | ||
this.firstInputValue = evt.detail.originalEvent.target.value; | ||
} | ||
|
||
private handleSecondInputChange(evt: any) { | ||
this.secondInputValue = evt.detail.originalEvent.target.value; | ||
} | ||
|
||
private handleCheckInput(evt: any) { | ||
this.checkBoxChecked = evt.detail.checkedState; | ||
} | ||
} | ||
|
||
if (!customElements.get(TAG_NAME)) { | ||
customElements.define(TAG_NAME, BlrFormExampleWithSlot); | ||
} | ||
|
||
export type BlrFormExampleWithSlotType = Omit<BlrFormExampleWithSlot, keyof LitElement>; |
7 changes: 7 additions & 0 deletions
7
packages/ui-library/src/components/form-example-with-slot/renderFunction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BlrFormExampleWithSlotType } from '.'; | ||
import { genericBlrComponentRenderer } from '../../utils/typesafe-generic-component-renderer'; | ||
|
||
export const TAG_NAME = 'blr-form-example-with-slot'; | ||
|
||
export const BlrFormExampleWithSlotRenderFunction = (params: BlrFormExampleWithSlotType) => | ||
genericBlrComponentRenderer<BlrFormExampleWithSlotType>(TAG_NAME, { ...params }); |
76 changes: 76 additions & 0 deletions
76
packages/ui-library/src/components/form-example-without-slot/index.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { typeSafeNestedCss as css } from "../../utils/nested-typesafe-css-literals"; | ||
import { renderThemedCssStrings } from "../../foundation/_tokens-generated/index.pseudo.generated"; | ||
|
||
export const { tokenizedLight: captionLight, tokenizedDark: captionDark } = renderThemedCssStrings((componentTokens) => { | ||
const { CaptionComponent } = componentTokens.Forms; | ||
|
||
return css` | ||
.blr-form-caption { | ||
width: 100%; | ||
display: flex; | ||
align-items: flex-start; | ||
color: ${CaptionComponent.Text.TextColor.Hint}; | ||
&.error { | ||
color: ${CaptionComponent.Text.TextColor.Error}; | ||
} | ||
&.sm { | ||
padding: ${CaptionComponent.Container.Padding.SM}; | ||
gap: ${CaptionComponent.Container.ItemSpacing.SM}; | ||
.blr-icon { | ||
padding-top: ${CaptionComponent.IconWrapper.PaddingTop.SM}; | ||
height: ${CaptionComponent.Icon.IconSize.SM}; | ||
width: ${CaptionComponent.Icon.IconSize.SM}; | ||
} | ||
.blr-caption-text { | ||
padding: ${CaptionComponent.TextWrapper.Padding.SM}; | ||
font-family: ${CaptionComponent.Text.Typography.SM.fontFamily}, sans-serif; | ||
font-weight: ${CaptionComponent.Text.Typography.SM.fontWeight}; | ||
font-size: ${CaptionComponent.Text.Typography.SM.fontSize}; | ||
line-height: ${CaptionComponent.Text.Typography.SM.lineHeight}; | ||
} | ||
} | ||
&.md { | ||
padding: ${CaptionComponent.Container.Padding.MD}; | ||
gap: ${CaptionComponent.Container.ItemSpacing.MD}; | ||
.blr-icon { | ||
padding-top: ${CaptionComponent.IconWrapper.PaddingTop.MD}; | ||
height: ${CaptionComponent.Icon.IconSize.MD}; | ||
width: ${CaptionComponent.Icon.IconSize.MD}; | ||
} | ||
.blr-caption-text { | ||
padding: ${CaptionComponent.TextWrapper.Padding.MD}; | ||
font-family: ${CaptionComponent.Text.Typography.MD.fontFamily}, sans-serif; | ||
font-weight: ${CaptionComponent.Text.Typography.MD.fontWeight}; | ||
font-size: ${CaptionComponent.Text.Typography.MD.fontSize}; | ||
line-height: ${CaptionComponent.Text.Typography.MD.lineHeight}; | ||
} | ||
} | ||
&.lg { | ||
padding: ${CaptionComponent.Container.Padding.LG}; | ||
gap: ${CaptionComponent.Container.ItemSpacing.LG}; | ||
.blr-icon { | ||
padding-top: ${CaptionComponent.IconWrapper.PaddingTop.LG}; | ||
height: ${CaptionComponent.Icon.IconSize.LG}; | ||
width: ${CaptionComponent.Icon.IconSize.LG}; | ||
} | ||
.blr-caption-text { | ||
padding: ${CaptionComponent.TextWrapper.Padding.LG}; | ||
font-family: ${CaptionComponent.Text.Typography.LG.fontFamily}, sans-serif; | ||
font-weight: ${CaptionComponent.Text.Typography.LG.fontWeight}; | ||
font-size: ${CaptionComponent.Text.Typography.LG.fontSize}; | ||
line-height: ${CaptionComponent.Text.Typography.LG.lineHeight}; | ||
} | ||
} | ||
} | ||
`; | ||
}); |
Oops, something went wrong.