1
1
import { html } from "lit" ;
2
2
import { ifDefined } from "lit/directives/if-defined.js" ;
3
+ import { unsafeHTML } from "lit/directives/unsafe-html.js" ;
3
4
4
5
import type { Meta , StoryFn } from "@storybook/web-components" ;
5
6
@@ -15,7 +16,7 @@ const component = "ui5-textarea";
15
16
let index = 0 ;
16
17
17
18
export default {
18
- title : "Main/TextArea " ,
19
+ title : "Main/Text Area " ,
19
20
component : "TextArea" ,
20
21
parameters : {
21
22
docs : {
@@ -42,35 +43,51 @@ const Template: UI5StoryArgs<TextArea, StoryArgsSlots> = (args) => html`
42
43
name ="${ ifDefined ( args . name ) } "
43
44
accessible-name ="${ ifDefined ( args . accessibleName ) } "
44
45
accessible-name-ref ="${ ifDefined ( args . accessibleNameRef ) } "
45
- > </ ui5-textarea > `;
46
+ >
47
+ ${ unsafeHTML ( args . valueStateMessage ) }
48
+ </ ui5-textarea > `;
46
49
47
- export const BasicTextArea = Template . bind ( { } ) ;
48
- BasicTextArea . args = {
49
- placeholder : 'Type as much text as you wish ' ,
50
+ export const Basic = Template . bind ( { } ) ;
51
+ Basic . args = {
52
+ placeholder : 'Enter text' ,
50
53
} ;
51
54
52
- export const TextAreaMaxLength = Template . bind ( { } ) ;
53
- TextAreaMaxLength . args = {
54
- placeholder : 'Type no more than 10 symbols' ,
55
+
56
+ export const WithMaxLength = Template . bind ( { } ) ;
57
+ WithMaxLength . decorators = [
58
+ ( story ) => html `
59
+ ${ story ( ) }
60
+ < script >
61
+ ( ( ) => {
62
+ const textAreaMaxLength = document . getElementById ( "textArea-${ index - 1 } " ) ;
63
+
64
+ textAreaMaxLength . addEventListener ( "input" , function ( event ) {
65
+ const { value, maxlength} = textAreaMaxLength ;
66
+ textAreaMaxLength . valueState = value . length > maxlength ? "Warning" : "None" ;
67
+ } ) ;
68
+ } ) ( )
69
+ </ script > `
70
+ ] ;
71
+ WithMaxLength . args = {
72
+ placeholder : 'Enter text' ,
55
73
maxlength : 10 ,
56
- showExceededText : true
74
+ showExceededText : true ,
75
+ valueStateMessage : `<div id="warningMessage" slot="valueStateMessage">The characters limit is exceeded</div>`
57
76
58
77
} ;
59
- TextAreaMaxLength . storyName = "Text Area with Maximum Length" ;
60
78
61
- export const TextAreaLabel = Template . bind ( { } ) ;
62
- TextAreaLabel . decorators = [
79
+ export const WithLabel = Template . bind ( { } ) ;
80
+ WithLabel . decorators = [
63
81
( story ) => {
64
82
return html `
65
83
< ui5-label for ="textArea- ${ index } "> Description</ ui5-label >
66
84
${ story ( ) }
67
85
` ;
68
86
}
69
87
]
70
- TextAreaLabel . args = {
88
+ WithLabel . args = {
71
89
placeholder : 'Enter description' ,
72
90
required : true
73
-
74
91
} ;
75
92
76
93
0 commit comments