Skip to content

Commit 04b8cab

Browse files
committed
use css custom properties for min and max height + update stories
1 parent 8069ed0 commit 04b8cab

File tree

2 files changed

+43
-83
lines changed

2 files changed

+43
-83
lines changed

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { ifDefined } from 'lit/directives/if-defined.js';
1010
* @fires UUITextareaEvent#change on change
1111
* @fires InputEvent#input on input
1212
* @fires KeyboardEvent#keyup on keyup
13+
* @cssprop --uui-textarea-min-height - Sets the minimum height of the textarea
14+
* @cssprop --uui-textarea-max-height - Sets the maximum height of the textarea
1315
*/
1416
export class UUITextareaElement extends LabelMixin(
1517
'textarea label',
@@ -56,10 +58,11 @@ export class UUITextareaElement extends LabelMixin(
5658
max-width: 100%;
5759
font-size: var(--uui-size-5);
5860
padding: var(--uui-size-2);
59-
border: 1px solid
60-
var(--uui-textarea-border-color, var(--uui-interface-border));
61+
border: 1px solid var(--uui-textarea-border-color, var(--uui-interface-border));
6162
border-radius: 0;
6263
outline: none;
64+
min-height: var(--uui-textarea-min-height);
65+
max-height: var(--uui-textarea-max-height);
6366
}
6467
#lengths-container {
6568
display: flex;
@@ -202,24 +205,6 @@ export class UUITextareaElement extends LabelMixin(
202205
@property({ type: Boolean, attribute: 'auto-height', reflect: true })
203206
autoHeight = false;
204207

205-
/**
206-
* Defines the minimum height of the textarea.
207-
* @type {string}
208-
* @attr
209-
* @default ''
210-
*/
211-
@property({ type: String })
212-
minHeight: String = '';
213-
214-
/**
215-
* Defines the maximum height of the textarea.
216-
* @type {string}
217-
* @attr
218-
* @default ''
219-
*/
220-
@property({ type: String })
221-
maxHeight: String = '';
222-
223208
private onInput(e: Event) {
224209
this.value = (e.target as HTMLInputElement).value;
225210
this.dispatchEvent(
@@ -267,6 +252,7 @@ export class UUITextareaElement extends LabelMixin(
267252
>${this.value ? this.value.length : 0}/${this.maxLength}</span
268253
>`;
269254
}
255+
270256
renderMinLength() {
271257
const shouldRender = this.minLength - this.value.length > 0;
272258
return shouldRender
@@ -282,7 +268,6 @@ export class UUITextareaElement extends LabelMixin(
282268
<textarea
283269
maxlength=${ifDefined(this.maxLength > 0 ? this.maxLength : undefined)}
284270
minlength=${this.minLength}
285-
style="min-height: ${this.minHeight}; max-height: ${this.maxHeight}"
286271
id="textarea"
287272
.value=${this.value}
288273
.name=${this.name}

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

Lines changed: 37 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ export default {
1313

1414
export const AAAOverview: Story = props =>
1515
html`<uui-textarea
16+
style="--uui-textarea-min-height: ${props['--uui-textarea-min-height']}; --uui-textarea-max-height: ${props['--uui-textarea-max-height']}"
1617
.label=${props.label}
1718
?auto-height=${props.autoHeight}
1819
.minLength=${props.minLength}
1920
.maxLength=${props.maxLength}
20-
.minHeight=${props.minHeight}
21-
.maxHeight=${props.maxHeight}
2221
.placeholder=${props.placeholder}
2322
?disabled=${props.disabled}
2423
.name=${props.name}
@@ -27,12 +26,18 @@ export const AAAOverview: Story = props =>
2726
?hide-label=${props.hideLabel}></uui-textarea>`;
2827

2928
AAAOverview.storyName = 'Overview';
29+
3030
AAAOverview.args = {
3131
label: 'Label',
32-
maxLength: 200,
33-
minHeight: '100px',
34-
maxHeight: '200px',
32+
'--uui-textarea-min-height': '',
33+
'--uui-textarea-max-height': '',
34+
};
35+
36+
AAAOverview.argTypes = {
37+
'--uui-textarea-min-height': { control: { type: 'text' } },
38+
'--uui-textarea-max-height': { control: { type: 'text' } },
3539
};
40+
3641
AAAOverview.parameters = {
3742
docs: {
3843
source: {
@@ -41,17 +46,16 @@ AAAOverview.parameters = {
4146
},
4247
};
4348

49+
4450
export const MaxLength: Story = props =>
45-
html`<uui-textarea
46-
label="textarea"
47-
maxLength=${props.maxLength}></uui-textarea>`;
51+
html`<uui-textarea label="Label" maxLength=${props.maxLength}></uui-textarea>`;
4852

4953
MaxLength.args = { maxLength: 20 };
5054
MaxLength.parameters = {
5155
controls: { include: ['maxLength'] },
5256
docs: {
5357
source: {
54-
code: `<uui-textarea label="textarea" maxLength="20"></uui-textarea>`,
58+
code: `<uui-textarea label="Label" maxLength="20"></uui-textarea>`,
5559
},
5660
},
5761
};
@@ -74,75 +78,46 @@ export const Placeholder: Story = props =>
7478
label="Label"
7579
placeholder=${props.placeholder}></uui-textarea>`;
7680

77-
Placeholder.args = { placeholder: 'I am a placeholder...' };
81+
Placeholder.args = { placeholder: 'Placeholder...' };
7882
Placeholder.parameters = {
7983
controls: { include: ['placeholder'] },
8084
docs: {
8185
source: {
82-
code: `<uui-textarea
83-
label="Label"
84-
placeholder="I am a placeholder..."></uui-textarea>`,
86+
code: `
87+
<uui-textarea
88+
label="Label"
89+
placeholder="Placeholder...">
90+
</uui-textarea>`,
8591
},
8692
},
8793
};
8894

89-
export const MaxAndMinHeight: Story = props =>
90-
html`<uui-textarea
91-
label="Label"
92-
minHeight=${props.minHeight}
93-
maxHeight=${props.maxHeight}></uui-textarea>`;
94-
95-
MaxAndMinHeight.args = { minHeight: '100px', maxHeight: '200px' };
96-
MaxAndMinHeight.parameters = {
97-
controls: { include: ['minHeight', 'maxHeight'] },
98-
docs: {
99-
source: {
100-
code: `<uui-textarea
101-
label="Label"
102-
minHeight="100px"
103-
maxHeight="200px"></uui-textarea>`,
104-
},
105-
},
106-
};
107-
108-
export const AutomaticHeightAdjustment: Story = props =>
109-
html` the height wil confine itself within the max and min height if defined.
95+
export const AutoHeight: Story = props =>
96+
html`
11097
<uui-textarea
11198
label="Label"
99+
style="--uui-textarea-min-height: ${props['--uui-textarea-min-height']}; --uui-textarea-max-height: ${props['--uui-textarea-max-height']}"
112100
?auto-height=${props.autoHeight}></uui-textarea>`;
113101

114-
AutomaticHeightAdjustment.args = { autoHeight: true };
115-
AutomaticHeightAdjustment.parameters = {
116-
controls: { include: ['autoHeight'] },
117-
docs: {
118-
source: {
119-
code: `<uui-textarea label="Label" auto-height></uui-textarea>`,
120-
},
121-
},
122-
};
123-
124-
export const AutomaticHeightAdjustmentWithHeightLimits: Story = props =>
125-
html` the height wil confine itself within the max and min height if defined.
126-
<uui-textarea
127-
label="Label"
128-
auto-height
129-
minHeight="100px"
130-
maxHeight="200px"></uui-textarea>`;
131-
132-
AutomaticHeightAdjustmentWithHeightLimits.args = {
133-
minHeight: '100px',
134-
maxHeight: '200px',
102+
AutoHeight.args = {
135103
autoHeight: true,
104+
'--uui-textarea-min-height': '100px',
105+
'--uui-textarea-max-height': '300px',
136106
};
137-
AutomaticHeightAdjustmentWithHeightLimits.parameters = {
138-
controls: { include: ['minHeight', 'maxHeight', 'autoHeight'] },
107+
108+
AutoHeight.parameters = {
109+
controls: { include: ['autoHeight', '--uui-textarea-min-height', '--uui-textarea-max-height'] },
139110
docs: {
111+
description: {
112+
story: "The height will confine itself within the max and min height if defined"
113+
},
140114
source: {
141-
code: `<uui-textarea
142-
label="Label"
143-
auto-height
144-
minHeight="100px"
145-
maxHeight="200px"></uui-textarea>`,
115+
code: `<uui-textarea label="Label" style="--uui-textarea-min-height: 100px; --uui-textarea-max-height: 300px;" auto-height></uui-textarea>`,
146116
},
147117
},
148118
};
119+
120+
AutoHeight.argTypes = {
121+
'--uui-textarea-min-height': { control: { type: 'text' } },
122+
'--uui-textarea-max-height': { control: { type: 'text' } },
123+
};

0 commit comments

Comments
 (0)