-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlawn.stories.js
55 lines (45 loc) · 1.23 KB
/
lawn.stories.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from 'react';
import Lawn from '../components/lawn';
export default {
title: 'Lawn',
component: Lawn,
};
const today = new Date(Date.UTC(2019, 0, 7));
function Template(args) {
return <Lawn {...args} />;
}
export const Empty = Template.bind({});
Empty.args = {
posts: [],
today,
};
export const Today = Template.bind({});
Today.args = {
posts: [{date: '2019-01-07', slug: '/2019-01-07-diary', textSize: 512}],
today,
};
export const Random = Template.bind({});
Random.args = (() => {
const posts = [];
const localToday = new Date(today);
/* eslint-disable-next-line unicorn/prefer-math-trunc, no-bitwise */
let x = localToday.getTime() | 0;
for (let i = 0; i <= 356; i++) {
const date = new Date(localToday.getTime());
date.setDate(date.getDate() - i);
const y = date.getFullYear();
const m = `${date.getMonth() + 1}`.padStart(2, '0');
const d = `${date.getDate()}`.padStart(2, '0');
const s = `${y}-${m}-${d}`;
/* eslint-disable-next-line unicorn/prefer-math-trunc, no-bitwise */
x = (x * 48_271) | 0;
if (x > 1000) {
posts.push({
date: s,
slug: `/${s}-diary`,
textSize: 2 ** ((x % 5) + 7),
});
}
}
return {posts, today};
})();