Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add property initializers #8846

Merged
merged 111 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
cd31931
feat: add property initializers
pskelin Nov 29, 2023
b80218f
chore: test
pskelin Apr 25, 2024
3da70de
chore: more components
pskelin Apr 25, 2024
9661a85
chore: add more components
pskelin Apr 25, 2024
98aa525
chore: more components
pskelin Apr 25, 2024
1732874
chore: few fiori components
Apr 25, 2024
1fc397f
chore: fix tests
pskelin Apr 26, 2024
7c11a49
chore: add check for missing type in decorator
pskelin Apr 26, 2024
f600e0f
chore: add more components
pskelin Apr 26, 2024
d6d832b
chore: few fiori components
Apr 26, 2024
257e667
chore: fiori fixes
Apr 26, 2024
da6aedf
chore: more components
pskelin Apr 26, 2024
caf98ab
chore: fix sidenavigation
Apr 26, 2024
dc9e62a
chore: add more components
pskelin Apr 26, 2024
693afd9
chore: list and list items
Apr 26, 2024
19ed3c6
chore: more components
pskelin Apr 26, 2024
cf91276
chore: input tests
Apr 26, 2024
76a8edc
chore: fix test
pskelin Apr 26, 2024
c258b8c
chore: fiori components
Apr 29, 2024
4ea56eb
chore: toolbar, tree
Apr 29, 2024
abe5573
chore: title,text,togglebutton
Apr 29, 2024
a2f9057
chore: fix attribute removal for undefined
pskelin Apr 29, 2024
9226546
chore: update lockfile chromedriver (#8837)
pskelin Apr 25, 2024
412d554
refactor(theming): remove Belize theme (#8519)
nnaydenow Apr 25, 2024
a3df694
fix(ui5-dialog): state icon no longer shrinks when title is too long …
dimovpetar Apr 25, 2024
1f96354
refactor(ui5-wizard): rename event parameter (#8845)
hristop Apr 26, 2024
bbe18e7
refactor(ui5-segmented-button-item): implement segmented button item …
tsanislavgatev Apr 26, 2024
da0a6f0
docs(ui5-upload-collection-item): improve uploadState property descri…
dimovpetar Apr 26, 2024
dfd483f
refactor(ui5-toast): replace `show` method with `open` property (#8855)
MapTo0 Apr 26, 2024
1d939b1
refactor: rename ValueState values (#8864)
ilhan007 Apr 27, 2024
a37f72c
docs: fix SegmentedButton multiple selection sample (#8869)
ilhan007 Apr 27, 2024
4420234
chore: add missing properties to ui5-segmented-button-item (#8870)
nnaydenow Apr 29, 2024
31125ef
chore: toast
Apr 29, 2024
52c9615
Merge remote-tracking branch 'origin' into prop-initializer
Apr 29, 2024
252299f
chore: more components
pskelin Apr 29, 2024
b1978a9
chore: more components
pskelin Apr 30, 2024
8b8a51f
Merge branch 'main' into prop-initializer
pskelin Apr 30, 2024
91c07e9
chore: fix ts error
pskelin Apr 30, 2024
a76808c
chore: slider, rangeslider
Apr 29, 2024
4d74b44
chore: toast
Apr 30, 2024
75b6364
chore: switch, tab, tabcontainer, textarea
Apr 30, 2024
c147e93
chore: table
Apr 30, 2024
28a2df2
chore: option, select, radiobutton, panel, selectmenu
May 2, 2024
fb6e114
chore: jsdoc
May 2, 2024
f0ffeac
Merge remote-tracking branch 'origin/main' into prop-initializer
May 2, 2024
715c413
chore: popopver, popup, responsive popover and few fixes
May 2, 2024
c056553
chore: fix dom reference attribute handling for HTMLElement
pskelin May 9, 2024
2bdaf2a
Merge branch 'main' into prop-initializer
pskelin May 9, 2024
41f8795
chore: add token, tokenizer, year picker
pskelin May 9, 2024
40393e6
chore: convert timepickers
pskelin May 9, 2024
36c2340
chore: convert suggestions
pskelin May 9, 2024
eaf2f9a
chore: fix ts error
pskelin May 9, 2024
0914462
chore: ts fixes
pskelin May 9, 2024
22f9e69
Merge branch 'main' into prop-initializer
pskelin May 9, 2024
dd8d894
chore: fix ts errors
pskelin May 9, 2024
5b4d120
chore: fix overflow calculation the old way
pskelin May 9, 2024
4fbc6a5
chore: fix popup closing to be sync
pskelin May 10, 2024
2a39cf2
Merge branch 'main' into prop-initializer
pskelin May 10, 2024
0786787
Merge branch 'main' into prop-initializer
pskelin May 15, 2024
046d1c8
chore: fixes
pskelin May 15, 2024
b3d0f1b
chore: fix TS errors
pskelin May 15, 2024
0e5af4a
chore: fix tokenizer test
pskelin May 15, 2024
3330d59
chore: extract DOMReference converter
pskelin May 15, 2024
7298109
Merge branch 'main' into prop-initializer
pskelin May 15, 2024
237d66a
chore: fix tab container test
pskelin May 15, 2024
283a47c
chore: fix bad merge
pskelin May 15, 2024
60c9611
chore: convert more components
pskelin May 15, 2024
f18b538
chore: ts fix
pskelin May 15, 2024
f34b9ec
Merge branch 'main' into prop-initializer
pskelin May 20, 2024
9efac49
Merge branch 'main' into prop-initializer
pskelin May 21, 2024
d2756a4
chore: select tooltip optional
pskelin May 21, 2024
d578d40
chore: fix test pages
pskelin May 23, 2024
9b860b1
Merge branch 'main' into prop-initializer
pskelin May 23, 2024
3026f68
chore: fix types
pskelin May 23, 2024
f6824c1
chore: fix bad merge
pskelin May 23, 2024
42c335d
chore: fix test
pskelin May 23, 2024
61ad28b
chore: color palette fix
pskelin May 27, 2024
941e612
chore: make select option value optional
pskelin May 27, 2024
ba9b02d
Merge branch 'main' into prop-initializer
pskelin May 27, 2024
52e8418
Merge branch 'main' into prop-initializer
pskelin May 29, 2024
7b600ef
chore: select test page string usage
pskelin May 29, 2024
525f6cc
Merge branch 'main' into prop-initializer
pskelin May 30, 2024
81c58a1
Merge branch 'main' into prop-initializer
pskelin Jun 4, 2024
6742594
chore: cleanup old defaultValue code
pskelin Jun 4, 2024
7235a16
chore: more fixes
pskelin Jun 4, 2024
c4a006e
chore: fix base test
pskelin Jun 4, 2024
1dc8c14
chore: fix base tests
pskelin Jun 4, 2024
5f82139
Merge branch 'main' into prop-initializer
pskelin Jun 4, 2024
c94da37
Merge branch 'main' into prop-initializer
pskelin Jun 10, 2024
b3f492d
chore: apply attributes synchronously after first rendering
pskelin Jun 12, 2024
5fcf2ad
Merge branch 'main' into prop-initializer
pskelin Jun 12, 2024
68e6656
chore: adapt new table
pskelin Jun 12, 2024
5e57c69
chore: update sync attribute logic
pskelin Jun 12, 2024
0420bd8
Merge branch 'main' into prop-initializer
pskelin Jun 12, 2024
fa1559a
Merge branch 'main' into prop-initializer
pskelin Jun 13, 2024
814c9d2
chore: improve initialized property handling
pskelin Jun 13, 2024
b883b73
chore: comment
pskelin Jun 17, 2024
99e6764
Merge branch 'main' into prop-initializer
pskelin Jun 17, 2024
d81a874
chore: import order
pskelin Jun 17, 2024
66aa424
chore: rename decorator
pskelin Jun 17, 2024
9515e3b
chore: restore button page
pskelin Jun 17, 2024
08d5c84
Merge branch 'main' into prop-initializer
pskelin Jun 19, 2024
ea7c683
chore: fix merge errors
pskelin Jun 19, 2024
53ae24e
Merge branch 'main' into prop-initializer
pskelin Jun 20, 2024
1ad2576
chore: cleanup
pskelin Jun 20, 2024
20f09fb
Merge branch 'main' into prop-initializer
pskelin Jun 20, 2024
3e6261a
Merge branch 'main' into prop-initializer
pskelin Jun 20, 2024
ff61b37
chore: convert remaining !
pskelin Jun 20, 2024
1e5cd02
Merge branch 'main' into prop-initializer
pskelin Jun 21, 2024
b6288e8
chore: update docs
pskelin Jun 21, 2024
bc89b30
Merge branch 'main' into prop-initializer
pskelin Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 53 additions & 66 deletions docs/5-development/03-understanding-components-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Defines the HTML tag for the Web Component.
tag: "my-component",
})
class MyComponent extends UI5Element {};
```
```



Expand Down Expand Up @@ -94,10 +94,10 @@ class MyComponent extends UI5Element {

## Properties / Attributes

Defines the HTML properties for the Web Component.
Defines the HTML properties for the Web Component.

**Note about attributes:** By default, for each property an equivalent attribute is supported. Attributes have the same names as properties, but in `kebab-case` rather than `camelCase`.
Properties of type `Object`, properties with `multiple` set to`true` and properties with `noAttribute` set to `true` do not have an attribute equivalent.
Properties of type `Object`, properties with `multiple` set to`true` and properties with `noAttribute` set to `true` do not have an attribute equivalent.

#### Example

Expand All @@ -107,79 +107,66 @@ Properties of type `Object`, properties with `multiple` set to`true` and propert
})
class DemoComponent extends UI5Element {

@property({ type: String, defaultValue: "Hello" })
message!: string;
@property()
message = "Hello"

@property({ type: Boolean, "noAttribute": true })
shown!: boolean;
shown = false

@property({ type: Object })
settings!: object;
settings: object = {};

@property({ validator: Integer })
animationDuration!: number;
@property({ type: Number })
animationDuration = 1000;

@property({ validator: Integer, "multiple": true })
nums!: Array<number>;
@property({ type: Array })
nums: Array<number> = []
};
```
```


#### @property configuration settings

| Setting | Type | Default | Description |
|----------------|------------------------------|-----------|---------------------------------------------------------------------------------------------------------------|
| `type` | Property type | String | The type of the property. For more information on types see the table below. |
| `defaultValue` | Any valid value for the type | undefined | Default value of the property. Cannot be set for type "Boolean". Booleans are always false by default in HTML.|
| `multiple` | Boolean | false | Indicates whether the property represents a single value or is an array of values of the given type. |
| `noAttribute` | Boolean | false | No attribute equivalent will be created for that property. Always true for properties of type Object. |
| `validator` | Validator type | N/A | The validator of the property. For more information on validators see the table below |
| Setting | Type | Default | Description |
| ------------- | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------ |
| `type` | Property type | String | The type of the property. For more information on types see the table below. |
| `noAttribute` | Boolean | false | No attribute equivalent will be created for that property. Always true for properties of type Object. |
| `converter` | Object | N/A | A custom converter with two methods - `fromAttribute` and `toAttribute` that will receive the `type` and the value |

**Note:** The `type` setting is required, except these two cases:
Types are used for attribute conversion only. Converting from a property to a string, the framework can check the runtime type and convert to string, but coming an attribute, there is no way to know whether it is a boolean or a number unless a type is also given.
**Note:** If `type` is omitted, it is implied to be `String`

- `string` properties (type: String is considered default)
#### Types

```ts
@property()
name!: string;
```
| Type | Class to Use | Description |
| ------- | ------------ | -------------------------------------------------------------------------- |
| string | `String` | Implied as default, should be omitted |
| boolean | `Boolean` | Boolean value, the presence of the attribute will set the property to true |
| number | `Number` | Number value, the attribute will be converted using `parseFloat` |
| object | `Object` | JS Object, equivalent to `noAttribute: true` |
| [] | `Array` | JS Array, equivalent to `noAttribute: true` |
| Enum | `String` | Enums are treated as strings, type does not accept enum types |

- `validator` is provided:
#### Initial values

Use property initializers to pass initial values
```ts
@property({ validator: Integer })
animationDuration!: number;
```


#### Types

| Type | Class to Use | Description |
|-------------|---------------------------------------------------------|-----------------------------------------|
| string | `String` | String value |
| boolean | `Boolean` | Boolean value - always false by default |
| object | `Object` | JS Object |
| custom type | Extend `@ui5/webcomponents-base/dist/types/DataType.js` | Used mainly for enumerations |

@property()
name = "user1";

#### Examples of prebuilt custom types
@property({ type: Boolean })
collapsed = false;

| Type | Class to Use | Description |
|------------|----------------------------------------------------|----------------------------------------------------------------|
| Integer | `@ui5/webcomponents-base/dist/types/Integer.js` | Integer value |
| ValueState | `@ui5/webcomponents-base/dist/types/ValueState.js` | Enumeration with: `None`, `Error`, `Warning`, `Success` values |
@property({ type: Number })
maxValue = 5;

#### Validators
@property({ type: Object })
accProperties = {};

The `validator` is a custom class that implements `isValid` function that validates the property's value whenever it changes. If value is not valid, the framework will set the proeprty `defaultValue`.
@property({ type: Array })
stars = [];
```

| Type | Class to Use | Description |
|-------------|----------------------------------------------------------|-----------------------------------------|
| number | `Integer` | Validates the prop value to integer |
| number | `Float` | Validates the prop value to float |
| string | `CSSColor` | Validates the prop value to valid CSS color|
| string | `CSSSize` | Validates the prop value to valid CSS size |
| string or HTMLElement | `DomReference` | Validates the prop value is it's a string or HTMLElement |

## Slots

Expand All @@ -205,18 +192,18 @@ class MyComponent extends UI5Element {

#### Slot configuration settings

| Setting | Type | Default | Description |
|------------------------------|-------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type` * | `HTMLElement` or `Node` | N/A | The type of the children that can go into that slot. |
| Setting | Type | Default | Description |
| ---------------------------- | ----------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` * | `HTMLElement` or `Node` | N/A | The type of the children that can go into that slot. |
| `individualSlots` | `Boolean` | false | If set to `true`, each child will have its own slot, allowing you to arrange/wrap the children arbitrarily. |
| `propertyName` | `String` | N/A | Allows to set the name of the property on the Web Component, where the children belonging to this slot will be stored. |
| `invalidateOnChildChange` ** | `Boolean` or `Object` | false | **Experimental, do not use.** Defines whether every invalidation of a UI5 Web Component in this slot should trigger an invalidation of the parent UI5 Web Component. |

`*` The `type` setting is required.

`**`
**Note:** `invalidateOnChildChange` is not meant to be used with standard DOM Elements and is not to be confused with `MutationObserver`-like functionality.
It rather targets the use case of components that slot abstract items (`UI5Element` instances without a template) and require to be invalidated in turn whenever these items are invalidated.
`**`
**Note:** `invalidateOnChildChange` is not meant to be used with standard DOM Elements and is not to be confused with `MutationObserver`-like functionality.
It rather targets the use case of components that slot abstract items (`UI5Element` instances without a template) and require to be invalidated in turn whenever these items are invalidated.

The `invalidateOnChildChange` setting can be either a `Boolean` (`true` meaning invalidate the component on any change of a child in this slot) or an `Object` with `properties` and `slots` fields. They in turn can be either of
type `Boolean` (`true` meaning invalidate on any property change or any slot change) or `Array` of strings indicating exactly which properties or slots lead to invalidation.
Expand Down Expand Up @@ -246,7 +233,7 @@ class MyComponent extends UI5Element {

```js
class MyComponent extends UI5Element {
@slot({
@slot({
type: HTMLElement,
invalidateOnChildChange: {
"properties": true,
Expand All @@ -261,7 +248,7 @@ class MyComponent extends UI5Element {

```js
class MyComponent extends UI5Element {
@slot({
@slot({
type: HTMLElement,
invalidateOnChildChange: {
"properties": ["text", "selected", "disabled"],
Expand All @@ -273,14 +260,14 @@ class MyComponent extends UI5Element {
```

Notes:
- Children without a `slot` attribute will be assigned to the `default` slot.
- Children without a `slot` attribute will be assigned to the `default` slot.
- All HTML text nodes will be assigned to the `default` slot, as they cannot have a `slot` attribute.
- For all slots the Web Component will have a property created, with the name of the slot, to hold a list of all children assigned to this slot.
For example, if you have a slot named "rows", "this.rows" will be an array, holding references to all children with `slot="rows"`, or no slot, if rows was default.
- For the `default` slot you can provide an accessor. In the following example, `this.items` will hold all children that were assigned to the default slot.

```ts
@slot({
@slot({
type: HTMLElement
"default": true,
})
Expand All @@ -290,8 +277,8 @@ items!: Array<HTMLElement>;

#### Slot types

| Type | Description |
|-------------|-------------------------------------------|
| Type | Description |
| ----------- | ----------------------------------------- |
| Node | Accepts both Text nodes and HTML Elements |
| HTMLElement | Accepts HTML Elements only |

Expand Down
Loading