Skip to content

Commit 5b00d58

Browse files
authored
Improve custom property value renderers' docs (#3370)
1 parent cbcfdbd commit 5b00d58

35 files changed

+185
-75
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@itwin/components-react",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@itwin/components-react"
10+
}

common/config/rush/browser-approved-packages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
},
289289
{
290290
"name": "@testing-library/react",
291-
"allowedCategories": [ "extensions", "frontend" ]
291+
"allowedCategories": [ "extensions", "frontend", "internal" ]
292292
},
293293
{
294294
"name": "@testing-library/react-hooks",

common/config/rush/pnpm-lock.yaml

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/changehistory/2.16.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ instance. The related instance, possibly being a of a different ECClass, might h
100100

101101
### Custom category renderers
102102

103-
[VirtualizedPropertyGrid]($components-react) now allows developers to fully customize displayed category contents, if the category is assigned a custom renderer via Presentation Rules. You can read more about that in our [Category customization learning page](../presentation/Customization/PropertyCategoryRenderers.md).
103+
[VirtualizedPropertyGrid]($components-react) now allows developers to fully customize displayed category contents, if the category is assigned a custom renderer via Presentation Rules. You can read more about that in our [Category customization learning page](../presentation/Content/PropertyCategoryRenderers.md).
104104

105105
### Custom category nesting
106106

docs/presentation/Customization/PropertyCategoryRenderers.md renamed to docs/presentation/Content/PropertyCategoryRenderers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This page explains how to leverage custom category renderers to create fully cus
44

55
## Defining a custom category
66

7-
To make use of custom category rendering system, we will need to define a custom category and assign it a renderer with Presentation Rules. This is achievable using [PropertyCategorySpecification](../Content/PropertyCategorySpecification.md):
7+
To make use of custom category rendering system, we will need to define a custom category and assign it a renderer with Presentation Rules. This is achievable using [PropertyCategorySpecification](./PropertyCategorySpecification.md):
88

99
```json
1010
...
@@ -20,7 +20,7 @@ To make use of custom category rendering system, we will need to define a custom
2020
...
2121
```
2222

23-
Now when `my_custom_category` is expanded, `my_custom_renderer` will be invoked to render properties assigned to this category. To learn more on property mapping to categories, visit [Property Categorization](../Content/PropertyCategorization.md) page.
23+
Now when `my_custom_category` is expanded, `my_custom_renderer` will be invoked to render properties assigned to this category. To learn more on property mapping to categories, visit [Property Categorization](./PropertyCategorization.md) page.
2424

2525
## Registering a custom renderer
2626

docs/presentation/Content/PropertyCategorySpecification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Custom category [renderer specification](./RendererSpecification.md) that allows
110110
in UI. This specification is used to set up [CategoryDescription.renderer]($presentation-common) for this category and it's up to
111111
the UI component to make sure appropriate renderer is used to render the category.
112112

113-
See [Custom property category renderers](../Customization/PropertyCategoryRenderers.md) page for information on how custom categories
113+
See [Custom property category renderers](./PropertyCategoryRenderers.md) page for information on how custom categories
114114
are handled in our UI components.
115115

116116
```ts

docs/presentation/Content/PropertySpecification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Custom property [renderer specification](./RendererSpecification.md) that allows
112112
specification is used to set up [Field.renderer]($presentation-common) for this property and it's up to the UI component to make sure
113113
appropriate renderer is used to render the property.
114114

115-
See [Custom property value renderers](../Customization/PropertyValueRenderers.md) page for a list of available renderers or how to register a custom one.
115+
See [Custom property value renderers](./PropertyValueRenderers.md) page for a list of available renderers or how to register a custom one.
116116

117117
```ts
118118
[[include:Content.Customization.PropertySpecification.Renderer.Ruleset]]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Custom property value renderers
2+
3+
Data in [PropertyGrid]($components-react) and [Table]($components-react) components is displayed by property value renderers. By defining and registering custom renderers, users can extend property rendering system to support new data types and UI interactions.
4+
5+
A custom renderer can be used by assigning it to specific properties through a property override. See [`PropertySpecification.renderer` section](../Content/PropertySpecification.md#attribute-renderer) for an example.
6+
7+
## Built-in renderers
8+
9+
iTwin.js UI and presentation packages register some built-in value renderers that can be used out of the box.
10+
11+
### `SelectableInstance`
12+
13+
> **Component:** [InstanceKeyValueRenderer]($presentation-components)
14+
>
15+
> **Prerequisites:**
16+
>
17+
> - Property value type is [Primitives.InstanceKey]($appui-abstract). Generally those are navigation type of properties.
18+
> - The property is rendered within a unified selection context. See [useUnifiedSelectionContext]($presentation-components) for more details.
19+
20+
The renderer renders nothing when property value is `undefined`. When it's defined, the value is rendered as a clickable text.
21+
22+
The property display value is used for the displayed text. If it is not set, then the [Type Converter](../../learning/ui/components/TypeConverters.md) system is used to calculate displayed string from the raw property value.
23+
24+
When the clickable text clicked on, the available unified selection context is used to replace active selection with the instance key stored in the value by calling [UnifiedSelectionContext.replaceSelection]($presentation-components).
25+
26+
| Default rendering | `SelectableInstance` rendering |
27+
| ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
28+
| ![Default navigation property value rendering](./media/property-value-renderers/default-navigation-property.png) | ![Selectable instance property value rendering](./media/property-value-renderers/selectable-instance.png) |
29+
30+
### `url`
31+
32+
> **Component:** [UrlPropertyValueRenderer]($components-react)
33+
>
34+
> **Prerequisites:**
35+
>
36+
> - Property type is one of [StandardTypeNames.URL]($appui-abstract), [StandardTypeNames.String]($appui-abstract) or [StandardTypeNames.Text]($appui-abstract).
37+
>
38+
> **Default for:** Properties with [StandardTypeNames.URL]($appui-abstract) type name. Generally those are properties with `"URI"` extended type in ECSchema.
39+
40+
The renderer renders nothing when property value is `undefined`. When it's defined, the value is rendered as a clickable text.
41+
42+
The property value is passed through the [Type Converter](../../learning/ui/components/TypeConverters.md) system to calculate displayed string. When the text clicked on, the user is navigated to the URL set to that text. **Note:** the renderer doesn't validate the text to really be a URL.
43+
44+
| Default rendering | `url` rendering |
45+
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
46+
| ![Default url property value rendering](./media/property-value-renderers/default-url-property.png) | ![Url property value rendering](./media/property-value-renderers/url.png) |
47+
48+
### `multiline`
49+
50+
> **Component:** [MultilineTextPropertyValueRenderer]($components-react)
51+
>
52+
> **Prerequisites:**
53+
>
54+
> - Property value is of primitive type.
55+
56+
The renderer renders nothing when property value is `undefined`. When it's defined, the value is passed through the [Type Converter](../../learning/ui/components/TypeConverters.md) system to calculate displayed string. The string is rendered in a single line with ellipsis and is allowed to be expanded into multiple lines to fit the whole string.
57+
58+
| Default rendering | `multiline` rendering |
59+
| -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
60+
| ![Default string property value rendering](./media/property-value-renderers/default-string-property.png) | ![Multiline collapsed property value rendering](./media/property-value-renderers/multiline-collapsed.png) ![Multiline expanded property value rendering](./media/property-value-renderers/multiline-expanded.png) |
61+
62+
## Adding a custom renderer
63+
64+
A new custom property value renderer can be added by registering a class implementing [IPropertyValueRenderer]($components-react) to the [PropertyValueRendererManager]($components-react):
65+
66+
```tsx
67+
[[include:Content.Customization.PropertySpecification.Renderer.Register]]
68+
```
69+
70+
The renderer registered above is used whenever a property with that renderer name is being rendered. The below ruleset demonstrates assigning the renderer to a property:
71+
72+
```ts
73+
[[include:Content.Customization.PropertySpecification.Renderer.Ruleset]]
74+
```
75+
76+
![Using a custom property value renderer](./media/property-value-renderers/custom.png)
Loading
Loading

0 commit comments

Comments
 (0)