Skip to content

Commit a07ec8f

Browse files
Allow custom element properties to have associated attributes (#75)
1 parent add283e commit a07ec8f

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2525
- Added an optional `"syntax"` field to CSSCustomProperty to describe the property syntax using CSS Properties and Values API's syntax strings. Fixes
2626
https://github.com/webcomponents/custom-elements-manifest/issues/68
2727

28+
- Added CustomElementField that extends ClassField with the ability to
29+
describe associated attributes. Fixes https://github.com/webcomponents/custom-elements-manifest/issues/36
30+
2831
<!-- ### Removed -->
2932
### Fixed
3033

schema.d.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ export interface SourceReference {
183183
* tagName, and another `Module` should contain the
184184
* `CustomElementExport`.
185185
*/
186-
export interface CustomElementDeclaration
187-
extends ClassDeclaration,
188-
CustomElement {}
186+
export type CustomElementDeclaration = ClassDeclaration & CustomElement;
189187

190188
/**
191189
* The additional fields that a custom element adds to classes and mixins.
@@ -226,8 +224,12 @@ export interface CustomElement extends ClassLike {
226224
* custom element class
227225
*/
228226
customElement: true;
227+
228+
members?: Array<CustomElementMember>;
229229
}
230230

231+
export type CustomElementMember = CustomElementField | ClassMethod;
232+
231233
export interface Attribute {
232234
name: string;
233235

@@ -328,9 +330,9 @@ export interface CssCustomProperty {
328330
*
329331
* The syntax must be a valid CSS [syntax string](https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax)
330332
* as defined in the CSS Properties and Values API.
331-
*
333+
*
332334
* Examples:
333-
*
335+
*
334336
* "<color>": accepts a color
335337
* "<length> | <percentage>": accepts lengths or percentages but not calc expressions with a combination of the two
336338
* "small | medium | large": accepts one of these values set as custom idents.
@@ -489,6 +491,23 @@ export interface ClassField extends PropertyLike {
489491
source?: SourceReference;
490492
}
491493

494+
/**
495+
* Additional metadata for fields on custom elements.
496+
*/
497+
export interface CustomElementField extends ClassField {
498+
/**
499+
* The corresponding attribute name if there is one.
500+
*/
501+
attribute?: string;
502+
503+
/**
504+
* If the property reflects to an attribute.
505+
*
506+
* If this is true, `attribute` must be defined.
507+
*/
508+
reflects?: boolean;
509+
}
510+
492511
export interface ClassMethod extends FunctionLike {
493512
kind: 'method';
494513
static?: boolean;
@@ -556,9 +575,7 @@ export interface MixinDeclaration extends ClassLike, FunctionLike {
556575
/**
557576
* A class mixin that also adds custom element related properties.
558577
*/
559-
export interface CustomElementMixinDeclaration
560-
extends MixinDeclaration,
561-
CustomElement {}
578+
export type CustomElementMixinDeclaration = MixinDeclaration & CustomElement;
562579

563580
export interface VariableDeclaration extends PropertyLike {
564581
kind: 'variable';

0 commit comments

Comments
 (0)