Skip to content

Commit e89a006

Browse files
committed
docs: rename data-type to data-types
1 parent 55ccfe2 commit e89a006

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

docs/pages/apis.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| `sx` | `SxProps` | - | [The `sx` prop](https://mui.com/system/getting-started/the-sx-prop/) lets you style elements inline, using values from the theme. |
1111
| `indentWidth` | `number` | 3 | Indent width for nested objects |
1212
| `keyRenderer` | `{when: (props) => boolean}` | - | Customize a key, if `keyRenderer.when` returns `true`. |
13-
| `valueTypes` | `ValueTypes` | - | Customize the definition of data types. See [Defining Data Types](/how-to/data-type) |
13+
| `valueTypes` | `ValueTypes` | - | Customize the definition of data types. See [Defining Data Types](/how-to/data-types) |
1414
| `onChange` | `(path, oldVal, newVal) => void` | - | Callback when value changed. |
1515
| `onCopy` | `(path, value) => void` | - | Callback when value copied, you can use it to customize the copy behavior.<br />\*Note: you will have to write the data to the clipboard by yourself. |
1616
| `onSelect` | `(path, value) => void` | - | Callback when value selected. |

docs/pages/how-to/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"data-type": "Defining Data Types",
2+
"data-types": "Defining Data Types",
33
"built-in-types": "Extend Built-in Data Types",
44
"styling": "Styling and Theming"
55
}

docs/pages/how-to/data-type.mdx renamed to docs/pages/how-to/data-types.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Tab, Tabs } from 'nextra-theme-docs'
22
import JsonViewerWithURL from '../../examples/JsonViewerWithURL'
33
import JsonViewerWithImage from '../../examples/JsonViewerWithImage'
44
import JsonViewerWithWidget from '../../examples/JsonViewerWithWidget'
5+
import JsonViewerCustomizeDate from '../../examples/JsonViewerCustomizeDate'
56

67
# Defining data types for any data
78

@@ -273,3 +274,37 @@ const linkType = defineDataType<string>({
273274
```
274275
</Tab>
275276
</Tabs>
277+
278+
### Customize the `Date` format
279+
280+
By default, `Date` values are displayed using the `toLocaleString` method. You will learn how to create a custom data type for `Date` and display it in a different format. We will use the enhanced `defineEasyType` function to simplify the process.
281+
282+
<Tabs items={['JS', 'TS']}>
283+
<Tab>
284+
```jsx
285+
import { defineEasyType } from '@textea/json-viewer'
286+
287+
const myDateType = defineEasyType({
288+
is: (value) => value instanceof Date,
289+
type: 'date',
290+
colorKey: 'base0D',
291+
Renderer: ({ value }) => <>{value.toISOString().split('T')[0]}</>
292+
})
293+
```
294+
</Tab>
295+
296+
<Tab>
297+
```tsx
298+
import { defineEasyType } from '@textea/json-viewer'
299+
300+
const myDateType = defineEasyType<Date>({
301+
is: (value) => value instanceof Date,
302+
type: 'date',
303+
colorKey: 'base0D',
304+
Renderer: ({ value }) => <>{value.toISOString().split('T')[0]}</>
305+
})
306+
```
307+
</Tab>
308+
</Tabs>
309+
310+
<JsonViewerCustomizeDate />

docs/pages/migration/migration-v3.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ npm install @mui/material @emotion/react @emotion/styled
2525

2626
`serialize` and `deserialize` have been added to datatype to support editing feature on any data type.
2727

28-
As the result, `createDataType` has been renamed to `defineDataType` and the signature has been changed to accept an object instead of a long list of arguments. For more information, please refer to [Defining data types](/data-type.mdx).
28+
As the result, `createDataType` has been renamed to `defineDataType` and the signature has been changed to accept an object instead of a long list of arguments. For more information, please refer to [Defining data types](/data-types.mdx).
2929

3030
```diff
3131
- createDataType(

src/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export type JsonViewerProps<T = unknown> = {
145145
/**
146146
* Customize the definition of data types.
147147
*
148-
* @see https://viewer.textea.io/how-to/data-type
148+
* @see https://viewer.textea.io/how-to/data-types
149149
*/
150150
valueTypes?: DataType<any>[]
151151
/** Callback when value changed. */

0 commit comments

Comments
 (0)