Storybook: date knob passes timestamp (number) instead of Date object

Created on 15 Apr 2017  ·  3Comments  ·  Source: storybookjs/storybook

Issue by jardakotesovec
_Thursday Oct 27, 2016 at 16:19 GMT_
_Originally opened as https://github.com/storybooks/storybook-addon-knobs/issues/68_


Is that intention? I would expect that inside component I will receive Date object and not timestamp.

knobs bug

All 3 comments

Comment by simon360
_Tuesday Feb 21, 2017 at 12:49 GMT_


It would be nice to have options here. I'd prefer to receive the date as an ISO8601 string, because of the way our component will be used. I'm not sure there's one correct type.

Perhaps an optional callback on date() which receives a Date as its input and returns whatever it wants, which is then passed on to the component. Could be a string, could be the Date, could be the timestamp. The current behaviour would remain as the default.

You should probably wrap the output of the knob in a way you find easy to deal with or your components expects. We can't please everyone, and there's too many ways to format a date.
A timestamp sounds perfectly reasonable to me.

Well, I suppose it has to return Date object because it's called date, right? It's very easy to retrieve epoch timestamp from Date object via default getTime method, but if you want to convert epoch time in ms into Date, it would not be that easy. Current implementation is misleading and inconsistent.

Was this page helpful?
0 / 5 - 0 ratings