Skip to content

Commit a04f774

Browse files
committed
Updated dnn-select to use dnn-fieldset
This PR updates dnn-select to consume the reusable dnn-fieldset component created earlier. This avoid code and styles duplications and will enhance maintainability. It also commits files from a full build that was missed earlier. Part of #992 work but does not complete it yet
1 parent ba9d315 commit a04f774

File tree

10 files changed

+82
-140
lines changed

10 files changed

+82
-140
lines changed

Diff for: packages/stencil-library/custom-elements.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"type": {
6262
"text": "\"button\" | \"reset\" | \"submit\""
6363
},
64-
"description": "Optional button type,\r\ncan be either submit, reset or button and defaults to button if not specified.\r\nWarning: DNN wraps the whole page in a form, only use this if you are handling\r\nform submission manually.",
64+
"description": "Optional button type,\ncan be either submit, reset or button and defaults to button if not specified.\nWarning: DNN wraps the whole page in a form, only use this if you are handling\nform submission manually.",
6565
"default": "'button'",
6666
"required": false
6767
},
@@ -88,7 +88,7 @@
8888
"type": {
8989
"text": "\"danger\" | \"primary\" | \"secondary\" | \"tertiary\""
9090
},
91-
"description": "Optional button style,\r\ncan be either primary, secondary or tertiary or danger and defaults to primary if not specified",
91+
"description": "Optional button style,\ncan be either primary, secondary or tertiary or danger and defaults to primary if not specified",
9292
"default": "'primary'",
9393
"required": false
9494
}
@@ -447,7 +447,7 @@
447447
"text": "{ contrast: string; preview: string; cancel: string; confirm: string; normal: string; light: string; dark: string; }"
448448
},
449449
"description": "Can be used to customize the text language.",
450-
"default": "{\r\n contrast: \"Contrast\",\r\n preview: \"Preview\",\r\n cancel: \"Cancel\",\r\n confirm: \"Confirm\",\r\n normal: \"Normal\",\r\n light: \"Light\",\r\n dark: \"Dark\",\r\n }",
450+
"default": "{\n contrast: \"Contrast\",\n preview: \"Preview\",\n cancel: \"Cancel\",\n confirm: \"Confirm\",\n normal: \"Normal\",\n light: \"Light\",\n dark: \"Dark\",\n }",
451451
"required": false
452452
}
453453
],
@@ -563,7 +563,7 @@
563563
"type": {
564564
"text": "boolean"
565565
},
566-
"description": "If true, will allow the user to take a snapshot\r\nusing the device camera. (only works over https).",
566+
"description": "If true, will allow the user to take a snapshot\nusing the device camera. (only works over https).",
567567
"default": "false",
568568
"required": false
569569
},
@@ -572,7 +572,7 @@
572572
"type": {
573573
"text": "number"
574574
},
575-
"description": "Specifies the jpeg quality for when the device\r\ncamera is used to generate a picture.\r\nNeeds to be a number between 0 and 1 and defaults to 0.8",
575+
"description": "Specifies the jpeg quality for when the device\ncamera is used to generate a picture.\nNeeds to be a number between 0 and 1 and defaults to 0.8",
576576
"default": "0.8",
577577
"required": false
578578
},
@@ -600,7 +600,7 @@
600600
"type": {
601601
"text": "string[]"
602602
},
603-
"description": "A list of allowed file extensions.\r\nIf not specified, any file is allowed.\r\nEx: [\"jpg\", \"jpeg\", \"gif\", \"png\"]",
603+
"description": "A list of allowed file extensions.\nIf not specified, any file is allowed.\nEx: [\"jpg\", \"jpeg\", \"gif\", \"png\"]",
604604
"required": false
605605
},
606606
{
@@ -807,7 +807,7 @@
807807
"kind": "class",
808808
"name": "dnn-image-cropper.tsx",
809809
"tagName": "dnn-image-cropper",
810-
"description": "Allows cropping an image in-browser with the option to enforce a specific final size.\r\nAll computation happens in the browser and the final image is emmited\r\nin an event that has a data-url of the image.",
810+
"description": "Allows cropping an image in-browser with the option to enforce a specific final size.\nAll computation happens in the browser and the final image is emmited\nin an event that has a data-url of the image.",
811811
"attributes": [
812812
{
813813
"name": "height",
@@ -859,7 +859,7 @@
859859
"type": {
860860
"text": "ImageCropperResx"
861861
},
862-
"description": "Can be used to customize controls text.\r\nSome values support tokens, see default values for examples.",
862+
"description": "Can be used to customize controls text.\nSome values support tokens, see default values for examples.",
863863
"required": false
864864
},
865865
{
@@ -916,7 +916,7 @@
916916
"type": {
917917
"text": "boolean"
918918
},
919-
"description": "If true, the browser default validation message will be hidden.",
919+
"description": "",
920920
"required": false
921921
},
922922
{
@@ -1135,7 +1135,7 @@
11351135
"type": {
11361136
"text": "string"
11371137
},
1138-
"description": "Optionally pass the aria-label text for the close button.\r\nDefaults to \"Close modal\" if not provided.",
1138+
"description": "Optionally pass the aria-label text for the close button.\nDefaults to \"Close modal\" if not provided.",
11391139
"default": "\"Close modal\"",
11401140
"required": false
11411141
},
@@ -1153,7 +1153,7 @@
11531153
"type": {
11541154
"text": "boolean"
11551155
},
1156-
"description": "Optionally you can pass false to not show the close button.\r\nIf you decide to do so, you should either not also prevent dismissal by clicking the backdrop\r\nor provide your own dismissal logic in the modal content.",
1156+
"description": "Optionally you can pass false to not show the close button.\nIf you decide to do so, you should either not also prevent dismissal by clicking the backdrop\nor provide your own dismissal logic in the modal content.",
11571157
"default": "true",
11581158
"required": false
11591159
},
@@ -1526,7 +1526,7 @@
15261526
"type": {
15271527
"text": "string"
15281528
},
1529-
"description": "Fires up each time the search query changes.\r\nThe data passed is the new query."
1529+
"description": "Fires up each time the search query changes.\nThe data passed is the new query."
15301530
}
15311531
],
15321532
"slots": [],
@@ -1550,7 +1550,7 @@
15501550
"type": {
15511551
"text": "boolean"
15521552
},
1553-
"description": "If true, the browser default validation message will be hidden.",
1553+
"description": "",
15541554
"required": false
15551555
},
15561556
{
@@ -1950,7 +1950,7 @@
19501950
"kind": "class",
19511951
"name": "dnn-vertical-splitview.tsx",
19521952
"tagName": "dnn-vertical-splitview",
1953-
"description": "This allows splitting a UI into vertical adjustable panels, the splitter itself is not part of this component.\r\n- The content for the left part should be injected in the `left` slot.\r\n- The content for the right part should be injected in the `right` slot.\r\n- The content for the actual splitter should go in the default slot and other UI elements can be injected as long as you handle their behaviour, by default only the drag behavior is implemented in the component.",
1953+
"description": "This allows splitting a UI into vertical adjustable panels, the splitter itself is not part of this component.\n- The content for the left part should be injected in the `left` slot.\n- The content for the right part should be injected in the `right` slot.\n- The content for the actual splitter should go in the default slot and other UI elements can be injected as long as you handle their behaviour, by default only the drag behavior is implemented in the component.",
19541954
"attributes": [
19551955
{
19561956
"name": "split-width-percentage",

Diff for: packages/stencil-library/src/components.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ export namespace Components {
507507
}
508508
interface DnnSelect {
509509
/**
510-
* If true, the browser default validation message will be hidden.
510+
* @deprecated This control has its own validatin reporting, will be removed in v0.25.0
511511
*/
512512
"disableValidityReporting": boolean;
513513
/**
@@ -1607,7 +1607,7 @@ declare namespace LocalJSX {
16071607
}
16081608
interface DnnSelect {
16091609
/**
1610-
* If true, the browser default validation message will be hidden.
1610+
* @deprecated This control has its own validatin reporting, will be removed in v0.25.0
16111611
*/
16121612
"disableValidityReporting"?: boolean;
16131613
/**

Diff for: packages/stencil-library/src/components/dnn-color-input/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ A custom input component that allows previewing and changing a color value.
6262

6363
### Depends on
6464

65+
- [dnn-fieldset](../dnn-fieldset)
6566
- [dnn-modal](../dnn-modal)
6667
- [dnn-tabs](../dnn-tabs)
6768
- [dnn-tab](../dnn-tab)
@@ -71,6 +72,7 @@ A custom input component that allows previewing and changing a color value.
7172
### Graph
7273
```mermaid
7374
graph TD;
75+
dnn-color-input --> dnn-fieldset
7476
dnn-color-input --> dnn-modal
7577
dnn-color-input --> dnn-tabs
7678
dnn-color-input --> dnn-tab

Diff for: packages/stencil-library/src/components/dnn-fieldset/readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,18 @@ Type: `Promise<void>`
124124

125125
### Used by
126126

127+
- [dnn-color-input](../dnn-color-input)
127128
- [dnn-example-form](../examples/dnn-example-form)
129+
- [dnn-input](../dnn-input)
130+
- [dnn-select](../dnn-select)
128131

129132
### Graph
130133
```mermaid
131134
graph TD;
135+
dnn-color-input --> dnn-fieldset
132136
dnn-example-form --> dnn-fieldset
137+
dnn-input --> dnn-fieldset
138+
dnn-select --> dnn-fieldset
133139
style dnn-fieldset fill:#f9f,stroke:#333,stroke-width:4px
134140
```
135141

Diff for: packages/stencil-library/src/components/dnn-input/readme.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A custom input component that wraps the html input element is a mobile friendly
1515
| -------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ----------- |
1616
| `allowShowPassword` | `allow-show-password` | If true, enables users to switch between a password and a text field (to view their password). | `boolean` | `undefined` |
1717
| `autocomplete` | `autocomplete` | Defines the type of auto-completion to use for this field, see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete. | `string` | `"off"` |
18-
| `disableValidityReporting` | `disable-validity-reporting` | If true, the browser default validation message will be hidden. | `boolean` | `undefined` |
18+
| `disableValidityReporting` | `disable-validity-reporting` | <span style="color:red">**[DEPRECATED]**</span> This control has it's own validation reporting, will be removed in v0.25.0<br/><br/> | `boolean` | `undefined` |
1919
| `disabled` | `disabled` | Defines whether the field is disabled. | `boolean` | `undefined` |
2020
| `helpText` | `help-text` | Defines the help label displayed under the field. | `string` | `undefined` |
2121
| `label` | `label` | The label for this input. | `string` | `undefined` |
@@ -96,9 +96,14 @@ Type: `Promise<void>`
9696

9797
- [dnn-example-form](../examples/dnn-example-form)
9898

99+
### Depends on
100+
101+
- [dnn-fieldset](../dnn-fieldset)
102+
99103
### Graph
100104
```mermaid
101105
graph TD;
106+
dnn-input --> dnn-fieldset
102107
dnn-example-form --> dnn-input
103108
style dnn-input fill:#f9f,stroke:#333,stroke-width:4px
104109
```

Diff for: packages/stencil-library/src/components/dnn-select/dnn-select.scss

+14-64
Original file line numberDiff line numberDiff line change
@@ -20,77 +20,27 @@
2020
--input-text-align: left;
2121
}
2222

23-
.container{
24-
border: 1px solid var(--foreground, #000);
25-
border-radius: var(--control-radius, 3px);
26-
padding: 0.75em;
23+
dnn-fieldset{
24+
width: 100%;
25+
}
26+
27+
.inner-container{
2728
display: flex;
2829
justify-content: space-between;
29-
gap: 0.1em;
3030
position: relative;
31+
width: 100%;
3132
background-color: var(--background);
32-
.inner-container{
33-
display: flex;
34-
justify-content: space-between;
35-
position: relative;
36-
width: 100%;
37-
background-color: var(--background);
38-
}
39-
label{
40-
display: inline-block;
41-
position: absolute;
42-
opacity: 0.6;
43-
transition: all 150ms ease-in-out;
44-
left: 0;
45-
top: 0;
46-
padding: 0 0.5em;
47-
background-color: var(--background);
48-
white-space: nowrap;
49-
max-width: 100%;
50-
border-radius: var(--control-radius);
51-
font-size: 1em;
52-
}
53-
select{
54-
border: none;
55-
outline: none;
56-
background-color: var(--background);
57-
text-align: var(--input-text-align);
58-
width: 100%;
59-
cursor: pointer;
60-
}
61-
label{
62-
opacity: 1;
63-
left: 0.5em;
64-
top: -1.5em;
65-
}
66-
&.focused{
67-
border: 1px solid var(--focus-color);
68-
box-shadow: 0 0 0 1px var(--focus-color);
69-
&.invalid{
70-
border: 1px solid var(--danger-color);
71-
box-shadow: 0 0 0 1px var(--danger-color);
72-
}
73-
74-
}
75-
&.disabled{
76-
opacity: 0.5;
77-
}
78-
&.invalid{
79-
border-color: var(--danger-color);
80-
}
8133
}
8234

83-
.help-text, .error-message{
84-
font-style: italic;
85-
opacity: 0.7;
86-
font-size: 0.8em;
87-
margin: 0.25em;
88-
}
89-
.error-message{
90-
color: var(--danger-color);
91-
font-style: normal;
92-
font-weight: bold;
35+
select{
36+
border: none;
37+
outline: none;
38+
background-color: var(--background);
39+
text-align: var(--input-text-align);
40+
width: 100%;
41+
cursor: pointer;
9342
}
43+
9444
.prefix, .suffix{
9545
font-size: 0.8em;
9646
}

Diff for: packages/stencil-library/src/components/dnn-select/dnn-select.tsx

+11-40
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export class DnnSelect {
2424
/** Defines whether the field is disabled. */
2525
@Prop() disabled: boolean;
2626

27-
/** If true, the browser default validation message will be hidden. */
27+
/** @deprecated This control has its own validatin reporting, will be removed in v0.25.0 */
2828
@Prop() disableValidityReporting: boolean;
2929

3030
/** The value of the input. */
3131
@Prop({mutable: true, reflect:true}) value: string;
3232

33-
@Element() el: HTMLElement;
33+
@Element() el: HTMLDnnSelectElement;
3434

3535
@State() focused: boolean = false;
3636
@State() valid = true;
@@ -67,6 +67,7 @@ export class DnnSelect {
6767
this.setFormValue();
6868
}
6969

70+
// eslint-disable-next-line @stencil-community/own-methods-must-be-private
7071
formResetCallback() {
7172
this.internals.setValidity({});
7273
this.value = this.originalValue;
@@ -85,38 +86,17 @@ export class DnnSelect {
8586
}
8687

8788
private setFormValue(){
88-
if (this.name){
89+
if (this.name != undefined){
8990
var data = new FormData();
9091
data.append(this.name, this.value);
9192
this.internals.setFormValue(data);
9293
}
9394
}
9495

95-
private getContainerClasses() {
96-
const classes = ["container"];
97-
98-
if (this.focused) {
99-
classes.push("focused");
100-
}
101-
102-
if (!this.valid){
103-
classes.push("invalid");
104-
}
105-
106-
if (this.disabled) {
107-
classes.push("disabled");
108-
}
109-
110-
return classes.join(" ");
111-
}
112-
11396
private handleChange(value: string) {
11497
this.value = value;
11598
var valid = this.select.checkValidity();
11699
this.valid = valid;
117-
if (!this.disableValidityReporting) {
118-
this.select.reportValidity();
119-
}
120100
this.valueChange.emit(this.value);
121101
this.setFormValue();
122102
}
@@ -131,16 +111,15 @@ export class DnnSelect {
131111
render() {
132112
return (
133113
<Host>
134-
<div
135-
class={this.getContainerClasses()}
114+
<dnn-fieldset
115+
invalid={!this.valid}
116+
focused={this.focused}
117+
label={`${this.label ?? ""}${this.required ? " *" : ""}`}
118+
helpText={this.helpText}
119+
id={this.labelId}
136120
onClick={() => !this.focused && this.select.focus()}
137121
>
138122
<div class="inner-container">
139-
{this.label &&
140-
<label id={this.labelId}>
141-
{`${this.label}${this.required ? " *" : ""}`}
142-
</label>
143-
}
144123
<select
145124
ref={el => this.select = el}
146125
onFocus={() => this.focused = true}
@@ -159,15 +138,7 @@ export class DnnSelect {
159138
</svg>
160139
}
161140
</div>
162-
</div>
163-
{!this.valid && this.customValidityMessage &&
164-
<div class="error-message">
165-
{this.customValidityMessage}
166-
</div>
167-
}
168-
{this.valid &&
169-
<div class="help-text">{this.helpText}</div>
170-
}
141+
</dnn-fieldset>
171142
</Host>
172143
);
173144
}

0 commit comments

Comments
 (0)