You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DIT-3689] Explicit support for list and map variables, misc cleanup (#28)
* chore: .env > .gitignore
* chore: update to latest version of Ditto CLI, `structured` format
* chore: add deprecation notices for API related to `full` format
* refactor: rm useless function
* add examples for new variable types, rm deprecated examples
* checkpoint;
* feat: better support specific variable types
* specific README additions for map and list variables
* always fallback to rendering provided input
* version bump
* small updates from PR feedback
If no value is provided for a variable, but that variable has a fallback value configured in the source data synced from Ditto (`structured` json format only), the fallback will be used:
112
112
113
113
```jsx
114
-
// if the variable `itemName` had "some fruit" configured as a fallback in Ditto
115
-
<Ditto textId={textId} variables={{}} />;
116
-
output ="The cart contains some fruit.";
117
-
```
118
-
119
-
```js
120
-
// ✔️ source contains variable information, interpolation will occur
|`projectId`| string (semi-required) | ID of a project in Ditto; required if a `projectId` isn't found in an ancestor `DittoProvider`|
246
-
|`textId`| string (optional) | ID of a single text item in Ditto ||
247
-
|`frameId`| string (optional) | ID of a frame in Ditto ||
248
-
|`blockId`| string (optional) | ID of a block in Ditto ||
249
-
|`filters`| object (optional) | object of filters for text items returned. Currently supports a single parameter: tags, an array of tag strings | { tags: ["SELECTS"]} |
250
-
|`variables`| object (optional) | A map of variable key-value pairs to interpolate in your text. | { email: "[email protected]" } |
251
-
|`count`| number (optional) | This value is used to specify which plural case you wish to use | 1 |
|`projectId`| string (semi-required) | ID of a project in Ditto; required if a `projectId` isn't found in an ancestor `DittoProvider`|
300
+
|`textId`| string (optional) | ID of a single text item in Ditto ||
301
+
|`frameId`| string (optional, **deprecated**)| ID of a frame in Ditto ||
302
+
|`blockId`| string (optional, **deprecated**)| ID of a block in Ditto ||
303
+
|`filters`| object (optional) | object of filters for text items returned. Currently supports a single parameter: tags, an array of tag strings | { tags: ["SELECTS"]} |
304
+
|`variables`| object (optional) | A map of variable key-value pairs to interpolate in your text. | { email: "[email protected]" } |
305
+
|`count`| number (optional) | This value is used to specify which plural case you wish to use | 1 |
252
306
253
307
##### Examples
254
308
@@ -261,7 +315,7 @@ If you pass `textId`, the specified text string will be rendered:
261
315
/>
262
316
```
263
317
264
-
If you pass `frameId` and/or `blockId`, the specified frame/block object will be passed to a child function:
318
+
**(deprecated)**If you pass `frameId` and/or `blockId`, **the specified** frame/block object will be passed to a child function:
265
319
266
320
```jsx
267
321
<Ditto
@@ -281,8 +335,8 @@ In addition to the `<Ditto />` component, individual exports of each specific co
281
335
282
336
```js
283
337
import {
284
-
DittoFrame,
285
-
DittoBlock,
338
+
DittoFrame,// deprecated
339
+
DittoBlock,// deprecated
286
340
DittoText,
287
341
DittoComponent, // rendering components from your Ditto component library
The `Ditto` component can be used to fetch a specific text item from the Ditto project using its API ID. Note that you can edit IDs for text, blocks, and frames directly the Ditto web app:
You can also iterate through the entire block (just as you can with any other object) to display each one.
348
-
349
-
```jsx
350
-
<Ditto frameId="header" blockId="navigation">
351
-
{(block) => {
352
-
returnObject.keys(block).map((id) => (
353
-
<div key={block[id]}>{block[id]}</div>
354
-
));
355
-
}}
356
-
</Ditto>
357
-
```
358
-
359
-
### Example: Fetch Frame
360
-
361
-
You can also fetch an entire Block in Ditto at once by just specifying the `frameId`. With it, you can fetch specific blocks, or iterate through all blocks and containing IDs as needed.
If you want to filter the text fetched by properties contained in the project itself, you can specify parameters to the `filter` prop of the `Ditto` component. This currently only supports the Tags field in Ditto, but will be expanded in the future to filter on any other metadata properties.
382
-
383
-
```jsx
384
-
// will only return text with the "TOP_NAV" tag
385
-
<Ditto
386
-
frameId="frame_601cc35d5be42cc3f6f8ad15"
387
-
blockId="navigation"
388
-
filters={{ tags: ["TOP_NAV"] }}
389
-
>
390
-
{(block) => {
391
-
returnObject.keys(block).map((id) => (
392
-
<div className={style.link} key={block[id]}>
393
-
{block[id]}
394
-
</div>
395
-
));
396
-
}}
397
-
</Ditto>
398
-
```
399
-
400
-
---
401
-
402
373
## Source
403
374
404
375
The React provider takes structured JSON outputs from Ditto as the source. These can be linked and automatically updated via [our API/CLI](https://github.com/dittowords/cli), or exported manually via the Ditto web app.
0 commit comments