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

Feat(ui-library): add storybook storie examples #343

Merged
merged 23 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
374474d
fix(ui-library): add storybook storie examples
JpunktWpunkt Sep 8, 2023
a4c72d2
feat(ui-library): adds hasError, disabled and default example to stor…
JpunktWpunkt Sep 8, 2023
0875c89
fix(ui-library): change the hint message
JpunktWpunkt Sep 11, 2023
ea08e2a
feat(ui-library): adds some example on one page and add font
JpunktWpunkt Sep 13, 2023
73b3abe
fix(ui-library): fix font issue
JpunktWpunkt Sep 13, 2023
71c09a5
feat(ui-library): adds dark theme to storybook storie, not yet compl…
JpunktWpunkt Sep 13, 2023
5cd4fb2
Merge branch 'develop' into feat/textarea-storybook
ChristianHoffmannS2 Sep 13, 2023
8a7d62c
Merge branch 'develop' into feat/textarea-storybook
ChristianHoffmannS2 Sep 13, 2023
08c1d85
core(ui-library): deleted some issues
JpunktWpunkt Sep 14, 2023
9921136
adds dark and lightmode status from storybook ui to show darkmode
JpunktWpunkt Sep 14, 2023
66253ac
adds some display flex to story
JpunktWpunkt Sep 14, 2023
c07ac74
fix(ui-libarary): adds some css values to try out the focus
JpunktWpunkt Sep 15, 2023
ceb6b6e
fix(ui-library): adds focus and blur
JpunktWpunkt Sep 20, 2023
7d1bca8
fix(ui-library): adds the structure from figma for showcase
JpunktWpunkt Sep 20, 2023
17c1fe4
fix(ui-library): fixed font size
JpunktWpunkt Sep 21, 2023
9b11e36
chore(ux-library): refactoring storybook story
JpunktWpunkt Sep 21, 2023
8651585
feat(ux-library): add lifecylce update for shouldFocusState
JpunktWpunkt Sep 21, 2023
2f71ca7
fix(ui-library): add new story to solve the focus issue
JpunktWpunkt Sep 21, 2023
9d0b570
fix(ui-library): fixed readonly issue
JpunktWpunkt Sep 21, 2023
ac2c570
fix(ux-library): change storybook title for showingcase
JpunktWpunkt Sep 21, 2023
84d4875
fix(ux-library): change storybook darkmode title color
JpunktWpunkt Sep 21, 2023
7f836af
fix(ui-library): fix some titles
JpunktWpunkt Sep 21, 2023
b674d90
chore(ux-library): cleaned up
JpunktWpunkt Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ui-library/src/components/text-input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class BlrTextInput extends LitElement {
class="blr-form-element ${inputClasses}"
id=${this.textInputId}
type="${this.currentType}"
value="${this.value}"
.value="${this.value}"
placeholder="${this.placeholder}"
?disabled="${this.disabled}"
?readonly="${this.readonly}"
Expand Down
278 changes: 278 additions & 0 deletions packages/ui-library/src/components/textarea/examples.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
import { html } from 'lit-html';
import { BlrTextareaRenderFunction, BlrTextareaType } from './index';
import './index';

const defaultParams: BlrTextareaType = {
theme: 'Light',
textareaId: '#1',
label: 'Label',
labelAppendix: '(Optional)',
size: 'md',
value: 'Rindfleischetikettierungsüberwachungsaufgabenübertragunsgesetz',
maxLength: 140,
warningLimitType: 'warningLimitInt',
warningLimitInt: 105,
warningLimitPer: 75,
cols: 20,
rows: 5,
shouldFocus: false,

placeholder: 'Type your message here ..',
required: false,
disabled: false,
readonly: false,

showHint: true,
hintIcon: 'blrInfo',
hintText: 'hint message',

hasError: false,
errorMessage: "OMG it's an error",

isResizeable: true,
};

interface StorybookTextareaType extends BlrTextareaType {
storybookLabel: string;
}

const fontStyle = html`
<style>
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap');
</style>
`;

export default {
title: 'Design System/Web Components/BlrTextarea/Examples',
parameters: {
viewMode: 'story',
previewTabs: {
'storybook/docs/panel': {
hidden: true,
},
},
},
argTypes: {
placeholder: {
name: 'Placeholder',
description: 'Defines a short hint intended to aid the user with data entry when the component has no value.',
defaultValue: '',
control: {
type: 'text',
label: 'Enter Text',
},
},
},
};

const renderTextareaExample = (params: StorybookTextareaType) => html`
<div class="story-textarea">
<p>${params.storybookLabel}</p>
${BlrTextareaRenderFunction(params)}
</div>
`;

export const Example1 = () => {
return html`
${fontStyle}
<style>
.wrapper {
font-family: 'Source Sans Pro', 'Source Code Pro', sans-serif;
display: flex;
width: 100%;
flex-wrap: wrap;
}
.stories-textarea {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.story-textarea {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
width: 20rem;
}
.column {
display: flex;
flex-direction: column;
}
</style>
<div class="wrapper">
<div class="column">
<p style="text-align: center">Default</p>
<div class="stories-textarea">
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Rest', theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Hover', theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Pressed', theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Focus', theme: 'Light', shouldFocus: true })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Disabled', theme: 'Light', disabled: true })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'readOnly', theme: 'Light', readonly: true })}
</div>
</div>
<div class="column">
<p style="text-align: center">Error</p>
<div class="stories-textarea">
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Rest', hasError: true, theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Hover', hasError: true, theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Pressed', hasError: true, theme: 'Light' })}
${renderTextareaExample({
...defaultParams,
storybookLabel: 'Focus',
hasError: true,
theme: 'Light',
shouldFocus: true,
})}
</div>
</div>
</div>
`;
};
Example1.parameters = {
backgrounds: {
default: 'light',
},
};

Example1.storyName = 'Textarea Examples Light Theme Focus Error';

export const Example4 = () => {
return html`
${fontStyle}
<style>
.wrapper {
font-family: 'Source Sans Pro', 'Source Code Pro', sans-serif;
display: flex;
width: 100%;
flex-wrap: wrap;
}
.stories-textarea {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.story-textarea {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
width: 20rem;
}
.column {
display: flex;
flex-direction: column;
}
</style>
<div class="wrapper">
<div class="column">
<p style="text-align: center">Default</p>
<div class="stories-textarea">
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Rest', theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Hover', theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Pressed', theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Focus', theme: 'Light', shouldFocus: true })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Disabled', theme: 'Light', disabled: true })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'readOnly', theme: 'Light', readonly: true })}
</div>
</div>
<div class="column">
<p style="text-align: center">Error</p>
<div class="stories-textarea">
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Rest', hasError: true, theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Hover', hasError: true, theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Pressed', hasError: true, theme: 'Light' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Focus', hasError: true, theme: 'Light' })}
</div>
</div>
</div>
`;
};
Example4.parameters = {
backgrounds: {
default: 'light',
},
};

Example4.storyName = 'Textarea Examples Light Theme Focus Default';

export const Example2 = () =>
html`
${fontStyle}
<style>
.wrapper {
font-family: 'Source Sans Pro', 'Source Code Pro', sans-serif;
display: flex;
width: 100%;
flex-wrap: wrap;
}

.stories-textarea {
display: flex;
color: white;
flex-wrap: wrap;
flex-direction: column;
}

.story-textarea {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
width: 20rem;
}
.column {
display: flex;
flex-direction: column;
}
</style>
<div class="wrapper">
<div class="column">
<p style="text-align: center; color: white">Default</p>
<div class="stories-textarea">
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Rest', theme: 'Dark' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Hover', theme: 'Dark' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Pressed', theme: 'Dark' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Focus', theme: 'Dark', shouldFocus: true })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Disabled', theme: 'Dark', disabled: true })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'readOnly', theme: 'Dark', readonly: true })}
</div>
</div>
<div class="column">
<p style="text-align: center; color: white">Error</p>
<div class="stories-textarea">
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Rest', hasError: true, theme: 'Dark' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Hover', hasError: true, theme: 'Dark' })}
${renderTextareaExample({ ...defaultParams, storybookLabel: 'Pressed', hasError: true, theme: 'Dark' })}
${renderTextareaExample({
...defaultParams,
storybookLabel: 'Focus',
hasError: true,
theme: 'Dark',
shouldFocus: true,
})}
</div>
</div>
</div>
`;
(Example2.parameters = {
backgrounds: {
default: 'dark',
},
}),
(Example2.storyName = 'Textarea Examples Dark Theme');

export const InteractivePlaceholder = ({ placeholder }) =>
html`
${fontStyle}
${BlrTextareaRenderFunction({
...defaultParams,
placeholder: placeholder,
value: '',
})}
`;
InteractivePlaceholder.storyName = 'Interaktiver Placeholder';
InteractivePlaceholder.args = {
placeholder: defaultParams.placeholder,
};
4 changes: 2 additions & 2 deletions packages/ui-library/src/components/textarea/index.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Themes } from '../../foundation/_tokens-generated/index.themes';
import { PureIconKeys } from '@boiler/icons';

export default {
title: 'Design System/Web Components',
title: 'Design System/Web Components/BlrTextarea',
argTypes: {
size: {
options: FormSizes,
Expand Down Expand Up @@ -121,7 +121,7 @@ export const BlrTextarea = ({
})}
`;

BlrTextarea.storyName = 'BlrTextarea';
BlrTextarea.storyName = 'BlrTextarea-Docs';

BlrTextarea.args = {
theme: 'Light',
Expand Down
27 changes: 20 additions & 7 deletions packages/ui-library/src/components/textarea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,22 @@ export class BlrTextarea extends LitElement {
@property() rows?: number;
@property() cols?: number;
@property() onSelect?: HTMLElement['onselect'];
@property() shouldFocus? = false;

@property() theme: ThemeType = 'Light';

@state() protected count = 0;

@query('textarea') protected textareaElement: HTMLTextAreaElement | undefined;

firstUpdated() {
if (this.shouldFocus) {
const textarea = this.shadowRoot?.querySelector('textarea');
if (textarea) {
textarea.focus();
}
}
}

connectedCallback() {
super.connectedCallback();

Expand Down Expand Up @@ -97,6 +106,7 @@ export class BlrTextarea extends LitElement {
[`error-input`]: this.hasError || false,
[`${this.size}`]: this.size,
[`resizeable`]: this.isResizeable || false,
['shouldFocus']: this.shouldFocus || false,
});

const counterVariant = this.determinateCounterVariant();
Expand Down Expand Up @@ -124,10 +134,13 @@ export class BlrTextarea extends LitElement {
placeholder="${this.placeholder || nothing}"
?required="${this.required}"
?disabled="${this.disabled}"
?readonly="${this.readonly}"
@input="${this.onChange}"
@focus="${this.onFocus}"
@focus=${this.focus}
@blur=${this.blur}
@select="${this.onSelect}"
@keyup="${this.updateCounter}"
shouldFocus="${this.shouldFocus}"
>${this.value}</textarea>
</div>
<div class="hint-wrapper">
Expand Down Expand Up @@ -163,8 +176,8 @@ export class BlrTextarea extends LitElement {
`;
}
}

export type BlrTextareaType = Omit<BlrTextarea, keyof LitElement>;
type OmittedKeys = 'firstUpdated';
export type BlrTextareaType = Omit<BlrTextarea, keyof LitElement | OmittedKeys>;

export const BlrTextareaRenderFunction = ({
textareaId,
Expand All @@ -185,13 +198,13 @@ export const BlrTextareaRenderFunction = ({
hintIcon,
hasError,
onChange,
onFocus,
onSelect,
readonly,
isResizeable,
showHint,
value,
theme,
shouldFocus,
}: BlrTextareaType) => {
return html`<blr-textarea
class=${isResizeable ? nothing : `parent-width`}
Expand All @@ -209,16 +222,16 @@ export const BlrTextareaRenderFunction = ({
.placeholder="${placeholder}"
.required=${required}
.disabled=${disabled}
.readOnly=${readonly}
.readonly=${readonly}
.hintText=${hintText}
.hintIcon=${hintIcon}
.hasError=${hasError}
.labelAppendix=${labelAppendix}
.onChange=${onChange}
.onFocus=${onFocus}
.onSelect=${onSelect}
.isResizeable=${isResizeable}
.showHint=${showHint}
.theme=${theme}
.shouldFocus=${shouldFocus}
></blr-textarea>`;
};
Loading