Skip to content

Commit a559aed

Browse files
committed
Get value from this.props.children
1 parent 1885da2 commit a559aed

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

README.md

+26-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
// Then, to use any ReactGlobalize component (with JSX)
2020
React.render(
21-
<FormatCurrency currency="USD" value={150}/>
21+
<FormatCurrency currency="USD">{150}</FormatCurrency>
2222
);
2323
// Which would render for example:
2424
// <span>$150.00</span> when using the `en` (English) locale, or
@@ -40,12 +40,14 @@ It allows to format a currency. Your code can be completely independent of the l
4040

4141
[currencyFormatter]: https://github.com/jquery/globalize/blob/master/doc/api/currency/currency-formatter.md
4242

43+
#### Children
44+
45+
The numeric value to be formatted. Required.
46+
4347
#### Props
4448

4549
- **currency** - required
4650
- A 3-letter string currency code as defined by ISO 4217 (e.g., USD, EUR, CNY, etc).
47-
- **value** - required
48-
- The numeric value to be formatted
4951
- **options**
5052
- An optional set of options to further format the value. See the [currencyFormatter][] docs in Globalize for more info on specific options
5153
- **locale** - optional
@@ -55,13 +57,13 @@ It allows to format a currency. Your code can be completely independent of the l
5557

5658
- Default format with USD in English
5759

58-
`<FormatCurrency currency="USD" value={150} />`
60+
`<FormatCurrency currency="USD">{150}</FormatCurrency>`
5961

6062
Result: `<span>$150.00</span>` when using the `en` (English) locale.
6163

6264
- Accounting format with EUR in Portuguese
6365

64-
`<FormatCurrency currency="EUR" value={-150} options={{ style: "accounting" }} />`
66+
`<FormatCurrency currency="EUR" options={{ style: "accounting" }}>{-150}</FormatCurrency>`
6567

6668
Result: `<span>(€150,00)</span>` when using the `pt` (Portuguese) locale.
6769

@@ -71,6 +73,10 @@ It allows to convert dates and times from their internal representations to text
7173

7274
[dateFormatter]: https://github.com/jquery/globalize/blob/master/doc/api/date/date-formatter.md
7375

76+
#### Children
77+
78+
The date object to be formatted. Required.
79+
7480
#### Props
7581

7682
- **value** - required
@@ -84,13 +90,13 @@ It allows to convert dates and times from their internal representations to text
8490

8591
- Simple string skeleton
8692

87-
`<FormatDate value={new Date()} options={{skeleton: "GyMMMd"}} />`
93+
`<FormatDate options={{skeleton: "GyMMMd"}}>{new Date()}</FormatDate>`
8894

8995
Result: `<span>Feb 27, 2015 AD</span>` when using the `en` (English) locale.
9096

9197
- Medium length date and time
9298

93-
`<FormatDate value={new Date()} options={{ datetime: "medium" }} />`
99+
`<FormatDate options={{ datetime: "medium" }}>{new Date()}</FormatDate>`
94100

95101
Result: `<span>27 de fev de 2015 11:17:10</span>` when using the `pt` (Portuguese) locale.
96102

@@ -101,6 +107,10 @@ It allows for the creation of internationalized messages (as defined by the [ICU
101107
[messageFormatter]: https://github.com/jquery/globalize/blob/master/doc/api/message/message-formatter.md
102108
[ICU Message syntax]: http://userguide.icu-project.org/formatparse/messages
103109

110+
#### Children
111+
112+
String or array path to traverse a set of messages store in JSON format. Required.
113+
104114
#### Props
105115

106116
- **path** - required
@@ -139,7 +149,7 @@ Below message JSON used in these examples:
139149
```
140150
- Simple salutation
141151

142-
Hi: `<FormatMessage path="salutations/hi" />`
152+
Hi: `<FormatMessage>{"salutations/hi"}</FormatMessage>`
143153

144154
Result:
145155

@@ -149,11 +159,11 @@ Result:
149159

150160
- Variable Replacement
151161

152-
Array: `<FormatMessage path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} />`
162+
Array: `<FormatMessage variables={["Wolfgang", "Amadeus", "Mozart"]}>{"variables/hello"}</FormatMessage>`
153163

154164
Result: `<span>Hello, Wolfgang Amadeus Mozart</span>` when using the `en` (English) locale.
155165

156-
Object in Portuguese: `<FormatMessage path="variables/hey" variables={{first:"Wolfgang", middle:"Amadeus", last:"Mozart"}} />`
166+
Object in Portuguese: `<FormatMessage variables={{first:"Wolfgang", middle:"Amadeus", last:"Mozart"}}>{"variables/hey"}</FormatMessage>`
157167

158168
Result: `<span>Ei, Wolfgang Amadeus Mozart</span>` when using the `pt` (Portuguese) locale.
159169

@@ -163,6 +173,10 @@ It allows to convert numbers into textual representations. Your code can be comp
163173

164174
[numberFormatter]: https://github.com/jquery/globalize/blob/master/doc/api/number/number-formatter.md
165175

176+
#### Children
177+
178+
The number to be formatted. Required.
179+
166180
#### Props
167181

168182
- **value** - required
@@ -176,13 +190,13 @@ It allows to convert numbers into textual representations. Your code can be comp
176190

177191
- Default format pi in English
178192

179-
`<FormatNumber locale="en" value={Math.PI} />`
193+
`<FormatNumber locale="en">{Math.PI}</FormatNumber>`
180194

181195
Result: `<span>3.142</span>` when using the `en` (English) locale.
182196

183197
- Show at least 2 decimal places in Portuguese
184198

185-
`<FormatNumber value={10000} options={{ minimumFractionDigits: 2 }} />`
199+
`<FormatNumber options={{ minimumFractionDigits: 2 }}>{10000}</FormatNumber>`
186200

187201
Result: `<span>10.000,00</span>` when using the `pt` (Portuguese) locale.
188202

src/generator.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ function generator(fn, argArray, options) {
2121
return componentProps[element];
2222
});
2323

24+
// Get value from this.props.children.
25+
this.args[0] = this.props.children;
26+
2427
if (this.props["locale"]) {
2528
this.instance = Globalize(this.props["locale"]);
2629
}

0 commit comments

Comments
 (0)