Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need support for DateTimeFormat/NumberFormat#formatToParts() #1048

Closed
zincli opened this issue Oct 16, 2017 · 12 comments · May be fixed by ajesse11x/dremio-oss#3
Closed

Need support for DateTimeFormat/NumberFormat#formatToParts() #1048

zincli opened this issue Oct 16, 2017 · 12 comments · May be fixed by ajesse11x/dremio-oss#3

Comments

@zincli
Copy link

zincli commented Oct 16, 2017

Is there any plan to support formatToParts()? We need this to style the price and the currency symbol...

Due to this issue#30 of ECMA402, formatToParts() already reached Stage 4. And the Intl Polyfill already have the implementations.

Maybe we could do some work to make this available in react-intl as an optional function?

@ericf I saw you in #30 and other related issues in react-intl. What do you think about this now?

@zincli zincli changed the title Need supportting for DateTimeFormat/NumberFormat#formatToParts() Need support for DateTimeFormat/NumberFormat#formatToParts() Oct 17, 2017
@stale
Copy link

stale bot commented May 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 30, 2019
@stale
Copy link

stale bot commented Jun 6, 2019

Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information.

@stale stale bot closed this as completed Jun 6, 2019
@tlvenn
Copy link

tlvenn commented Aug 19, 2019

@zincli can you please re-open, pretty interested to see some support for this as well.

@longlho longlho reopened this Aug 20, 2019
@stale stale bot removed the wontfix label Aug 20, 2019
@longlho
Copy link
Member

longlho commented Aug 20, 2019

@zincli @tlvenn can u guys provide some use cases?

@tlvenn
Copy link

tlvenn commented Aug 20, 2019

This was a pretty compelling use case: #874

@longlho
Copy link
Member

longlho commented Aug 22, 2019

hmm I'm considering adding a new component like <FormattedDateParts> instead of overloading <FormattedDate> so we can keep the types sane. WDYT?

cc @redonkulus

@redonkulus
Copy link
Member

@longlho What would the API look like for this?

@longlho
Copy link
Member

longlho commented Aug 22, 2019

<FormattedDateParts>
	{(parts: Intl.DateTimeFormatPart[]) => (
		<b>{parts[0]}</b>
		{parts[1]}
		<small>{parts[2]}</small>
	)}
</FormattedDateParts>

although I'd like to learn more about this use case, because ordering of the parts along w/ length of the parts is non-deterministic (bc of different locale + bidi) so styling might be tricky? @tlvenn

@robrichard
Copy link
Contributor

I think correct usage would be something like this:

<FormattedDateParts>
    {parts => parts.map(part => 
        <span className={`number-part-${part.type}`}>{part.value}<span>
    )}
</FormattedDateParts>
.number-part-integer {
    font-size: 14px;
}

.number-part-fraction {
    font-size: 10px;
}

@longlho
Copy link
Member

longlho commented Aug 23, 2019

yeah I got that, but I feel like the styling would still be fairly inconsistent cross-locale

image

Anw, this does fit w/ the intention of the original formatToParts proposal and supporting it isn't too bad so I've added it to the backlog.

3.2 is looking like this feature + /~https://github.com/formatjs/formatjs/tree/master/packages/intl-unified-numberformat would make it

@longlho
Copy link
Member

longlho commented Aug 30, 2019

react-intl@next should have this.

@mrijke
Copy link
Contributor

mrijke commented Dec 31, 2019

What about a formatDateParts() function next to /~https://github.com/formatjs/react-intl/blob/master/docs/API.md#formatdate ? Or is this already available some other way in cases where using the <FormattedDate> component is not possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants