Skip to content

Commit a5a56c7

Browse files
author
samgarasx
committed
Update kotlin-react-intl wrapper to v5.20.13
1 parent a744d9b commit a5a56c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1075
-692
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ kotlin-styled.version=5.3.1-pre.258
88

99
kotlin-antd.version=4.8.6-pre.15
1010
kotlin-moment.version=2.29.1-pre.14
11-
kotlin-react-intl.version=5.8.1-pre.13
11+
kotlin-react-intl.version=5.20.13-pre.14
1212
kotlin-react-responsive.version=8.1.0-pre.13
1313
kotlin-uikit.version=3.5.7-pre.12

kotlin-react-intl/react-intl-samples/src/main/kotlin/samples/Advanced.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import kotlinx.css.fontSize
55
import kotlinx.css.px
66
import react.*
77
import react.dom.*
8-
import reactintl.message.*
9-
import reactintl.provider.*
8+
import reactintl.components.message.formattedMessage
9+
import reactintl.components.provider.intlProvider
1010
import styled.css
1111
import styled.styledSpan
1212
import kotlin.js.Date

kotlin-react-intl/react-intl-samples/src/main/kotlin/samples/App.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class App : RComponent<Props, State>() {
3636
hooks()
3737
handleChange()
3838
advanced()
39+
bug272()
3940
}
4041
}
4142
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package samples
2+
3+
import kotlinx.browser.window
4+
import kotlinx.html.js.onClickFunction
5+
import kotlinx.html.title
6+
import react.Props
7+
import react.RBuilder
8+
import react.dom.*
9+
import react.fc
10+
import react.useState
11+
import reactintl.components.provider.intlProvider
12+
import reactintl.components.relativetime.formattedRelativeTime
13+
import reactintl.components.useIntl
14+
import kotlin.js.Date
15+
16+
private fun getRelativeTime(date: Date): Number {
17+
return (date.getTime() - Date().getTime()) / 1000
18+
}
19+
20+
external interface PostDateProps : Props {
21+
var date: Date
22+
}
23+
24+
private val postDate = fc<PostDateProps> { props ->
25+
val intl = useIntl()
26+
27+
span {
28+
attrs.title = intl.formatDate(props.date)
29+
formattedRelativeTime {
30+
attrs {
31+
value = getRelativeTime(props.date)
32+
updateIntervalInSeconds = 1
33+
}
34+
}
35+
}
36+
}
37+
38+
private val app = fc<Props> {
39+
val (hide, setHide) = useState(false)
40+
41+
intlProvider {
42+
attrs.locale = window.navigator.language
43+
div {
44+
h1 { +"Hello world" }
45+
if (!hide) {
46+
p {
47+
postDate { attrs.date = Date() }
48+
}
49+
}
50+
button {
51+
attrs.onClickFunction = {
52+
setHide { current -> !current }
53+
}
54+
+"Toggle FormattedRelativeTime"
55+
}
56+
}
57+
}
58+
}
59+
60+
fun RBuilder.bug272() = child(app)

kotlin-react-intl/react-intl-samples/src/main/kotlin/samples/HandleChange.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import kotlinx.html.js.*
77
import react.*
88
import react.dom.*
99
import reactintl.*
10+
import reactintl.components.provider.createIntl
11+
import reactintl.components.rawIntlProvider
1012

11-
private val intlMessages = run {
13+
private val appMessages = run {
1214
val messages = js {}
1315

1416
messages["en-US"] = js { selectlanguage = "Select a language" }
@@ -23,7 +25,7 @@ private val cache = createIntlCache()
2325

2426
var intl = createIntl(jsObject {
2527
locale = initialLocale
26-
messages = intlMessages.asDynamic()[initialLocale].unsafeCast<Any>()
28+
messages = appMessages.asDynamic()[initialLocale].unsafeCast<Any>()
2729
}, cache)
2830

2931
private val app = fc<Props> {
@@ -32,7 +34,7 @@ private val app = fc<Props> {
3234
val changeLanguage = fun(newLocale: String) {
3335
intl = createIntl(jsObject {
3436
locale = newLocale
35-
messages = intlMessages.asDynamic()[newLocale].unsafeCast<Any>()
37+
messages = appMessages.asDynamic()[newLocale].unsafeCast<Any>()
3638
}, cache)
3739

3840
document.documentElement.asDynamic()["lang"] = newLocale
@@ -52,7 +54,7 @@ private val app = fc<Props> {
5254
changeLanguage(it.target.asDynamic().value as String)
5355
}
5456
}
55-
Object.keys(intlMessages).map { locale ->
57+
Object.keys(appMessages).map { locale ->
5658
option {
5759
attrs {
5860
key = locale

kotlin-react-intl/react-intl-samples/src/main/kotlin/samples/Hooks.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package samples
33
import kotlinext.js.*
44
import react.*
55
import react.dom.*
6-
import reactintl.*
7-
import reactintl.provider.*
6+
import reactintl.components.provider.intlProvider
7+
import reactintl.components.useIntl
88
import kotlin.js.Date
99
import kotlin.random.*
1010

kotlin-react-intl/react-intl-samples/src/main/kotlin/samples/Injected.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import kotlinext.js.*
44
import react.*
55
import react.dom.*
66
import reactintl.*
7-
import reactintl.provider.*
7+
import reactintl.components.WrappedComponentProps
8+
import reactintl.components.injectIntl
9+
import reactintl.components.provider.intlProvider
10+
import reactintl.components.useIntl
811
import kotlin.js.Date
912

1013
private val comp = fc<Props> {
@@ -17,15 +20,13 @@ external interface Comp2Props : WrappedComponentProps<Any> {
1720
var intl: IntlShape
1821
}
1922

20-
private class Comp2 : RComponent<Comp2Props, State>() {
21-
override fun RBuilder.render() {
22-
h1 { +props.intl.formatDate(Date.now(), jsObject { month = "long" }) }
23-
h2 { +props.intl.formatTime(undefined) }
24-
}
23+
private val comp2 = fc<Comp2Props> { props ->
24+
h1 { +props.intl.formatDate(Date.now(), jsObject { month = "long" }) }
25+
h2 { +props.intl.formatTime(Date()) }
2526
}
2627

2728
fun RBuilder.comp2WithIntl(handler: RHandler<Comp2Props>) =
28-
child(injectIntl<Any, Comp2Props>(Comp2::class.js), jsObject {}, handler)
29+
child(injectIntl<Any, Comp2Props>(comp2), jsObject {}, handler)
2930

3031
private val app = fc<Props> {
3132
intlProvider {

kotlin-react-intl/react-intl-samples/src/main/kotlin/samples/Messages.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package samples
33
import kotlinext.js.*
44
import react.*
55
import react.dom.*
6-
import reactintl.message.*
7-
import reactintl.provider.*
6+
import reactintl.components.message.formattedMessage
7+
import reactintl.components.provider.intlProvider
88
import kotlin.js.Date
99
import kotlin.random.*
1010

11-
private val providerMessages = js {
11+
private val appMessages = js {
1212
simple = "Hello world"
1313
placeholder = "Hello {name}"
1414
date = "Hello {ts, date}"
@@ -31,7 +31,7 @@ private val app = fc<Props> {
3131
intlProvider {
3232
attrs {
3333
locale = "en"
34-
messages = providerMessages
34+
messages = appMessages
3535
}
3636
p {
3737
formattedMessage { attrs.id = "simple" }
@@ -130,7 +130,7 @@ private val app = fc<Props> {
130130
strong { +chunks }
131131
}
132132
}
133-
}.unsafeCast<Any>()
133+
}
134134
}
135135
}
136136
br {}
@@ -144,7 +144,7 @@ private val app = fc<Props> {
144144
strong { +chunks }
145145
}
146146
}
147-
}.unsafeCast<Any>()
147+
}
148148
}
149149
}
150150
br {}

kotlin-react-intl/react-intl-samples/src/main/kotlin/samples/TimeZone.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package samples
22

33
import react.*
44
import react.dom.*
5-
import reactintl.datetime.*
6-
import reactintl.provider.*
5+
import reactintl.components.datetime.IntlDateTime
6+
import reactintl.components.datetime.formattedDate
7+
import reactintl.components.datetime.formattedDateParts
8+
import reactintl.components.datetime.formattedTime
9+
import reactintl.components.provider.intlProvider
710
import kotlin.js.*
811

912
external interface TimeZoneProps : Props {
@@ -34,7 +37,7 @@ private val app = fc<TimeZoneProps> { props ->
3437
month = "long"
3538
day = "2-digit"
3639
}
37-
childList += fun(parts: Array<IntlDateTimeFormatPart>): ReactElement {
40+
childList += fun(parts: Array<IntlDateTime.DateTimeFormatPart>): ReactElement {
3841
return buildElement {
3942
span {
4043
b { +parts[0].value }

kotlin-react-intl/src/main/kotlin/reactintl/Elements.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package reactintl
22

3-
import reactintl.datetime.*
4-
import reactintl.number.*
5-
import reactintl.plural.*
3+
import reactintl.components.datetime.*
4+
import reactintl.components.number.*
5+
import reactintl.components.plural.*
66

77
external enum class MessageType {
88
LITERAL,
@@ -49,7 +49,7 @@ external interface SelectElement : BaseElement<MessageType> {
4949
external interface PluralElement : BaseElement<MessageType> {
5050
var options: Any
5151
var offset: Number
52-
var pluralType: PluralRuleType
52+
var pluralType: IntlPluralRuleType
5353
}
5454

5555
external interface PoundElement : BaseElement<MessageType>
@@ -58,14 +58,14 @@ external interface DateTimeSkeleton {
5858
var type: MessageSkeletonType
5959
var pattern: String
6060
var location: Location?
61-
var parsedOptions: IntlDateTimeFormatOptions
61+
var parsedOptions: IntlDateTime.DateTimeFormatOptions
6262
}
6363

6464
external interface NumberSkeleton {
6565
var type: MessageSkeletonType
6666
var tokens: Array<NumberSkeletonToken>
6767
var location: Location?
68-
var parsedOptions: IntlNumberFormatOptions
68+
var parsedOptions: IntlNumber.NumberFormatOptions
6969
}
7070

7171
external interface NumberSkeletonToken {

0 commit comments

Comments
 (0)