|
| 1 | +import Head from "next/head"; |
| 2 | +import { ThemeProvider, injectGlobal } from "styled-components"; |
| 3 | +import { offcourse as theme } from "../themes"; |
| 4 | +import { Card, Heading, Group, Button, Masonry, Text } from "@offcourse/atoms"; |
| 5 | +import { AppShell } from "@offcourse/organisms"; |
| 6 | + |
| 7 | +injectGlobal([theme.globals]); |
| 8 | +const text = ` |
| 9 | + Lorem ipsum dolor amet small batch heirloom thundercats sartorial irony crucifix. Butcher locavore cloud bread humblebrag meh celiac hexagon biodiesel sustainable kale chips messenger bag. Ramps forage next level leggings, retro kale chips disrupt photo booth shaman farm-to-table cornhole neutra bicycle rights cred woke. Vexillologist cornhole vape, subway tile microdosing sartorial jianbing authentic biodiesel. Portland pop-up shabby chic gastropub mlkshk bushwick shoreditch before they sold out craft beer coloring book. |
| 10 | +`; |
| 11 | +const text1 = ` |
| 12 | + Butcher locavore cloud bread humblebrag meh celiac hexagon biodiesel sustainable kale chips messenger bag. |
| 13 | +`; |
| 14 | +const text2 = ` |
| 15 | + Ramps forage next level leggings, retro kale chips disrupt photo booth shaman farm-to-table cornhole neutra bicycle rights cred woke. Vexillologist cornhole vape, subway tile microdosing sartorial jianbing authentic biodiesel." |
| 16 | +`; |
| 17 | +const text3 = ` |
| 18 | + Portland pop-up shabby chic gastropub mlkshk bushwick shoreditch before they sold out craft beer coloring book. |
| 19 | +`; |
| 20 | +const text4 = text; |
| 21 | + |
| 22 | +const randInt = (min, max) => { |
| 23 | + return Math.floor(Math.random() * (max - min + 1)) + min; |
| 24 | +}; |
| 25 | + |
| 26 | +const createFragment = () => { |
| 27 | + return text.slice(randInt(0, 160), randInt(300, 600)).trim(); |
| 28 | +}; |
| 29 | + |
| 30 | +const fragments = [text2, text4, text1, text3]; |
| 31 | + |
| 32 | +class Content extends React.Component { |
| 33 | + state = { items: fragments }; |
| 34 | + |
| 35 | + render() { |
| 36 | + const sizes = [ |
| 37 | + { columns: 1, gutter: 16 }, |
| 38 | + { mq: "650px", columns: 2, gutter: 16 }, |
| 39 | + { mq: "975px", columns: 3, gutter: 16 }, |
| 40 | + { mq: "1300px", columns: 4, gutter: 16 }, |
| 41 | + { mq: "1625px", columns: 5, gutter: 16 }, |
| 42 | + { mq: "1950px", columns: 6, gutter: 16 } |
| 43 | + ]; |
| 44 | + |
| 45 | + const { items } = this.state; |
| 46 | + |
| 47 | + return ( |
| 48 | + <div style={{ padding: "16px" }}> |
| 49 | + <Masonry sizes={sizes}> |
| 50 | + {({ forcePack }) => |
| 51 | + items.map((fragment, index) => ( |
| 52 | + <Card key={index}> |
| 53 | + <Heading size="small" section="title"> |
| 54 | + {`Masonry Example ${index + 1}`} |
| 55 | + </Heading> |
| 56 | + <Group section="body"> |
| 57 | + <Text size="small">{fragment}</Text> |
| 58 | + </Group> |
| 59 | + <Button |
| 60 | + size="large" |
| 61 | + variant="warning" |
| 62 | + onClick={() => { |
| 63 | + const newItems = [...items]; |
| 64 | + newItems.push(createFragment()); |
| 65 | + this.setState({ items: newItems }); |
| 66 | + forcePack(); |
| 67 | + }} |
| 68 | + > |
| 69 | + Add Item |
| 70 | + </Button> |
| 71 | + </Card> |
| 72 | + )) |
| 73 | + } |
| 74 | + </Masonry> |
| 75 | + </div> |
| 76 | + ); |
| 77 | + } |
| 78 | +} |
| 79 | +class App extends React.Component { |
| 80 | + state = { |
| 81 | + isOpen: false |
| 82 | + }; |
| 83 | + |
| 84 | + render() { |
| 85 | + const toggle = () => this.setState({ isOpen: !this.state.isOpen }); |
| 86 | + const links = [ |
| 87 | + { |
| 88 | + href: "https://condescending-wing-149611.netlify.com/", |
| 89 | + title: "Contribute", |
| 90 | + level: 3 |
| 91 | + } |
| 92 | + ]; |
| 93 | + |
| 94 | + return ( |
| 95 | + <ThemeProvider theme={theme}> |
| 96 | + <AppShell |
| 97 | + position="absolute" |
| 98 | + onLogoClick={toggle} |
| 99 | + toggleSidebar={toggle} |
| 100 | + isSidebarOpen={this.state.isOpen} |
| 101 | + links={links} |
| 102 | + > |
| 103 | + <Head> |
| 104 | + <meta |
| 105 | + name="viewport" |
| 106 | + content="width=device-width, initial-scale=1" |
| 107 | + /> |
| 108 | + </Head> |
| 109 | + <Content /> |
| 110 | + </AppShell> |
| 111 | + </ThemeProvider> |
| 112 | + ); |
| 113 | + } |
| 114 | +} |
| 115 | +export default App; |
0 commit comments