11import type { } from 'element-internals-polyfill' ;
2+ import { ElementInternals } from 'element-internals-polyfill/dist/element-internals' ;
23import { Constructor } from 'web-utility/source/data' ;
34import { BaseFieldProps , CustomFormElement } from 'web-utility/source/DOM-type' ;
45
56import { WebCellProps } from './utility' ;
67import { mixin , WebCellComponent } from './WebCell' ;
7- import { watch , attribute } from './decorator' ;
8+ import { attribute } from './decorator' ;
89
910export interface WebFieldProps extends BaseFieldProps , WebCellProps { }
1011
11- export type WebFieldComponent <
12+ export interface WebFieldState {
13+ disabled ?: boolean ;
14+ }
15+
16+ export interface WebFieldComponent <
1217 P extends WebFieldProps = WebFieldProps ,
1318 S = { }
14- > = CustomFormElement & WebCellComponent < P , S > ;
19+ > extends CustomFormElement ,
20+ WebCellComponent < P , S > {
21+ internals : ElementInternals ;
22+ }
1523
1624export type WebFieldClass <
1725 P extends WebFieldProps = WebFieldProps ,
1826 S = { }
1927> = Constructor < WebFieldComponent < P , S > > ;
2028
21- export function mixinForm < P extends WebFieldProps = WebFieldProps , S = { } > (
22- superClass : Constructor < HTMLElement > = HTMLElement
23- ) : WebFieldClass < P , S > {
24- class WebField
25- extends mixin < P , S > ( superClass )
26- implements WebFieldComponent < P , S > {
29+ export function mixinForm <
30+ P extends WebFieldProps = WebFieldProps ,
31+ S extends WebFieldState = WebFieldState
32+ > ( ) : WebFieldClass < P , S > {
33+ class WebField extends mixin < P , S > ( ) implements WebFieldComponent < P , S > {
2734 static formAssociated = true ;
2835
29- @attribute
30- @watch
31- name : string ;
36+ readonly internals = this . attachInternals ( ) ;
3237
33- @watch
34- value : string ;
38+ formDisabledCallback ( disabled : boolean ) {
39+ this . setState ( { disabled } as Partial < S > ) ;
40+ }
3541
3642 @attribute
37- @watch
38- required : boolean ;
43+ set name ( name : string ) {
44+ this . setProps ( { name } as Partial < P > ) ;
45+ }
46+ get name ( ) {
47+ return this . props . name ;
48+ }
49+
50+ set value ( value : string ) {
51+ this . setProps ( { value } as Partial < P > ) ;
52+ this . internals . setFormValue ( value ) ;
53+ }
54+ get value ( ) {
55+ return this . props . value ;
56+ }
3957
4058 @attribute
41- @watch
42- disabled : boolean ;
59+ set required ( required : boolean ) {
60+ this . setProps ( { required } as Partial < P > ) ;
61+ }
62+ get required ( ) {
63+ return this . props . required ;
64+ }
4365
4466 @attribute
45- @watch
46- placeholder : string ;
67+ set disabled ( disabled : boolean ) {
68+ this . setProps ( { disabled } as Partial < P > ) ;
69+ }
70+ get disabled ( ) {
71+ return this . props . disabled ;
72+ }
4773
4874 @attribute
49- @watch
50- autofocus : boolean ;
75+ set autofocus ( autofocus : boolean ) {
76+ this . setProps ( { autofocus } as Partial < P > ) ;
77+ }
78+ get autofocus ( ) {
79+ return this . props . autofocus ;
80+ }
5181
5282 set defaultValue ( raw : string ) {
5383 this . setAttribute ( 'value' , raw ) ;
@@ -59,8 +89,6 @@ export function mixinForm<P extends WebFieldProps = WebFieldProps, S = {}>(
5989 return this . getAttribute ( 'value' ) ;
6090 }
6191
62- protected internals = this . attachInternals ( ) ;
63-
6492 get form ( ) {
6593 return this . internals . form ;
6694 }
0 commit comments