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
Copy file name to clipboardExpand all lines: README.md
+54-52Lines changed: 54 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,16 @@
1
-
2
-
3
1
# react-text-renderer-components
4
2
5
3
! MANAGE YOUR DATA, NOT THEIR STRING REPRESENTATION !
6
4
7
-
This is a zero-dependencies component library providing a set of (pure) text rendering utility components. Those components are accepting common and custom data/field types as input and are rendering their text representation *automatically*.
5
+
This is a zero-dependencies component library providing a set of (pure) text rendering utility components. Those components are accepting common and custom data/field types as input and are rendering their text representation _automatically_.
8
6
9
7
e.g. to render the text corresponding to a `DateOfBirth` field (Date type) within an html-table cell, use a simple `<td><DateRenderer value={person.DateOfBirth} /></td>` statement.
## Storybook, Changelog and Release note Documentation
18
16
@@ -39,41 +37,43 @@ more components to come... (see the ToDos below)
39
37
40
38
- typesafe handling of input values = use your own input value types!
41
39
- text formating is implemented within the text-renderer react components
42
-
- (automatic) rendering of Date, Time and DateTime (w/ optional custom format) *localized* text representations
43
-
- render formated text as-is i.e. as "*pure*" text (e.g.`new Date("06.10.2024")` rendered as `06.10.2024`) or
40
+
- (automatic) rendering of Date, Time and DateTime (w/ optional custom format) _localized_ text representations
41
+
- render formated text as-is i.e. as "_pure_" text (e.g. `new Date("06.10.2024")` rendered as `06.10.2024`) or
44
42
- render formated text within a `<span></span>` tag (e.g. `new Date("06.10.2024")` rendered as `<span>06.10.2024</span>`)
45
-
- implement *your own (reusable) Text Renderer components* easily (see below)
46
-
- efficient and type safe formating of *Date* values using the `Intl.DateTimeFormat(..)` (see "Notes on formating DateTime values" below)
43
+
- implement _your own (reusable) Text Renderer components_ easily (see below)
44
+
- efficient and type safe formating of _Date_ values using the `Intl.DateTimeFormat(..)` (see "Notes on formating DateTime values" below)
47
45
- define once, reuse everywhere
48
46
- use the CustomRenderer component to render any type of data using a simple 'mutation' function of your own (not implemented yet).
49
47
50
48
more features to come (see the ToDos below)
51
49
52
50
## Installation
53
51
54
-
The package containing the Text Renderer Components will be available for installation using *either* the [NPM package registry](https://www.npmjs.com/search?q=react-text-renderer-components)*or* the Github Packages as registered directly within the Github repository of the library.
52
+
The package containing the Text Renderer Components will be available for installation using _either_ the [NPM package registry](https://www.npmjs.com/search?q=react-text-renderer-components)_or_ the Github Packages as registered directly within the Github repository of the library.
55
53
56
54
### install from the "npm registry"
57
55
58
56
You may use any package manager cli such as "npm" or "yarn" in order to download and install the library in your project.
59
57
60
58
1. From the root folder of your project (containing the `package.json` file of the project), run the following command within any suitable shell (powershell, bash...):
61
59
62
-
```shell
63
-
npm install react-text-renderer-components
60
+
```shell
61
+
npm install react-text-renderer-components
64
62
65
-
# or
63
+
# or
64
+
65
+
yarn install react-text-renderer-components
66
+
```
66
67
67
-
yarn install react-text-renderer-components
68
-
```
69
68
1. import any component you'd like to use and insert the corresponding tag and options into your rendering procedure:
70
-
```jsx
71
-
import { DateRenderer } from '@khatastroffik/react-text-renderer-components';
&logo=react&logoColor=%2361DAFB&labelColor=%2320232a)
85
+
&logo=react&logoColor=%2361DAFB&labelColor=%2320232a>)
**Note:***The"class inheritance" is intentionally used here*!
97
+
**Note:**_The "class inheritance" is intentionally used here_!
98
98
99
99
This design allows to avoid repetitions, reduce the size of the compiled code using this library, ease maintenance of the components. It also simplify type checking (potentially complex) data/value types and separate the user interface from the "business logic" of the different renderer classes etc. It also permit to validate/sanitize/escape the rendered text centraly, regardless of the implemented Text Renderer classes.
100
100
@@ -103,7 +103,7 @@ This design allows to avoid repetitions, reduce the size of the compiled code us
103
103
### Implement supplemental renderer components
104
104
105
105
- ✅ `WeekRenderer` component
106
-
- ⬛`QuarterRenderer` component
106
+
-✅`QuarterRenderer` component
107
107
- ⬛ `TextRenderer` component (with text manipulation like UpperCase, LowerCase, Replace...)
108
108
- ⬛ `CurrencyRenderer` component
109
109
- ⬛ `CustomRenderer` component i.e the text formating function may be provided from the parent application/component using the CustomRenderer.
@@ -122,7 +122,9 @@ This design allows to avoid repetitions, reduce the size of the compiled code us
122
122
- ✅ cache usage of `Intl.DateTimeFormat(..)` within the Date based renderers
123
123
- ✅ add a `timeZone` property to the Date based renderers
124
124
- ✅ document "UTC" requirement on Date values
125
-
- ✅ Add `numberingSystem` option to WeekRenderer component (`01/2026` is `༠༡/༢༠༢༦` using *Tibetan* digits → siehe [standard Unicode numeral systems](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems#supported_numbering_system_types))
125
+
- ✅ Add `numberingSystem` option to WeekRenderer component (`01/2026` is `༠༡/༢༠༢༦` using _Tibetan_ digits → see [standard Unicode numeral systems](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems#supported_numbering_system_types))
126
+
- ⬛ Add an option to display ISO week numbers and quarter number as "ordinal numbers" (referring to the ordering or ranking of things, e.g. "1st", "2nd", "3rd" in English) →
127
+
see [Plural Rules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules)
126
128
127
129
### project enhancements
128
130
@@ -133,12 +135,12 @@ This design allows to avoid repetitions, reduce the size of the compiled code us
133
135
- ✅ add a github action in order to deploy the package as github package within the repository
134
136
- ✅ add a github action in order to build and publish the storybook static page as github page of the repository
135
137
- ✅ provide an example for implementing custom components derived from the AbstractRenderer component
136
-
- ✅ implement automatic changelog and release note creation
138
+
- ✅ implement automatic changelog and release note creation
137
139
138
140
## How to implement your own, custom "renderer" using this library?
139
141
140
142
it is very easy to implement new classes derived from the `AbstractRenderer` class:
141
-
143
+
142
144
- such derived classes just need to provide an implementation of the abstract `getFormatedText(): string` method.
143
145
- Optionally, the type of the input `value` property (default to string) can be set/defined using a simplistic interface declaration.
144
146
- Furthermore, you may define additional properties for the derived react component.
// do whatever you like with the additional property
212
-
return this.value ?? this.icon;
213
-
}
212
+
protected getFormatedText():string {
213
+
// do whatever you like with the additional property
214
+
returnthis.value??this.icon;
215
+
}
214
216
}
215
217
```
216
218
@@ -245,7 +247,7 @@ A standard approach consists in calling one of the formating methodes of the `Da
245
247
246
248
There's a potential **negative impact** of using this approach when dealing with large amount of data i.e. a lot of "to-be-formated" date values, as stated in the [MSDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString) documentation:
247
249
248
-
> Every time toLocaleString is called, it has to perform a search in a big database of localization strings, which is *potentially inefficient*. When the method is called many times with the same arguments, it is better to create a Intl.DateTimeFormat object and use its format() method, because a DateTimeFormat object remembers the arguments passed to it and may decide to cache a slice of the database, so future format calls can search for localization strings within a more constrained context.
250
+
> Every time toLocaleString is called, it has to perform a search in a big database of localization strings, which is _potentially inefficient_. When the method is called many times with the same arguments, it is better to create a Intl.DateTimeFormat object and use its format() method, because a DateTimeFormat object remembers the arguments passed to it and may decide to cache a slice of the database, so future format calls can search for localization strings within a more constrained context.
249
251
250
252
Hence, this library is using the `DateTimeFormat` object and its `format()`method to generate localized and formated output (according to the renderer component properties) as per:
- The values and options used/available within the "Control" column are for demonstration purpose only.
24
+
- Use the "Reset controls" button on the top right side of the table in order to restore the initial demo values and options. Alternatively, you could reload the page.
25
+
26
+
### Usage
27
+
28
+
<Sourcedarktype={"jsx"}code={`
29
+
import { QuarterRenderer } from 'react-text-renderer-components';
30
+
31
+
const Example = () => {
32
+
return <QuarterRenderer value={new Date()} />
33
+
}`
34
+
} />
35
+
36
+
Back to the [Github Repository](https://github.com/khatastroffik/react-text-renderer-components)
description: "The **value** from which the quarter should be rendered.",
17
+
},
18
+
pure: {
19
+
control: "boolean",
20
+
description: "If **pure** is set/defined, then the component will render nothing but the 'pure' text representation of the value. Otherwise, the text representation is embeded within a *<span></span>* tag. (default: false/unset)",
21
+
},
22
+
displayYear: {
23
+
control: "boolean",
24
+
description: "Should the year corresponding to the Quarter number be displayed (e.g. '3/2026')? (default: false/unset)"
description: {component: "The **QuarterRenderer** component displays the **Quarter number** corresponding to the input *value* of type `Date` (UTC). The displayed string is either pure or *spanned* i.e. enclosed by a *<span></span>* tag. Optionally, the year corresponding to the calculated Quarter number can be disaplyed as well (e.g. '2/2026')."},
0 commit comments