Skip to content

Commit

Permalink
feat: Add Article and Image components (#56)
Browse files Browse the repository at this point in the history
* Add some things

* Add case/switch

* Add test

* Image component

* Add Image doc

* ci(travis): add a missing colon

* refactor(Article): Fix some syntax

* export ImageProps

* Add usage details

* ../Image

* Update snapshot
  • Loading branch information
nathanmsmith authored and ryang72 committed Oct 11, 2018
1 parent 14a2397 commit ea78c64
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 22 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2

This comment has been minimized.

Copy link
@zeehang

zeehang Oct 15, 2018

Contributor

Is there a specific reason we took out indent size of 2?

end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

Lux is a design system for the Daily Bruin, written in [TypeScript](https://www.typescriptlang.org) and [React](https://reactjs.org).

## Usage

To use Lux, simply install it with your favorite package manager, e.g.:

```
yarn add @dailybruin/lux
```

Import components with the following syntax:

```javascript
import { Article } from '@dailybruin/lux'
```

## Development

To start a dev server for the docs:
Expand Down
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,css,md}": [
"prettier --write",
"git add"
],
"*.{ts,tsx}": [
"tslint"
],
"*": [
"eclint check"
"linters": {
"*.{js,jsx,ts,tsx,json,css,md}": [
"prettier --write",
"git add"
],
"*.{ts,tsx}": [
"tslint"
],
"*": [
"eclint check"
]
},
"ignore": [
"**/dist/*",
"*.test.*"
]
},
"scripts": {
Expand Down
29 changes: 29 additions & 0 deletions src/components/Article/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Article Matches its snapshot 1`] = `
<article>
<p>
<strong>
Lorem
</strong>
<a
href="https://dailybruin.com"
>
ipsum
</a>
dolor sit amet, consectetur adipiscing elit. Cras porttitor metus in pellentesque bibendum. Fusce rutrum sollicitudin finibus. Proin pellentesque leo enim, sed ultrices diam laoreet ut. Vivamus ut consequat nulla. Aenean sodales enim ut sapien rhoncus, in rhoncus metus mattis. Phasellus sed turpis tristique, tristique augue quis, lobortis est. Proin consectetur volutpat lacus, vitae luctus orci eleifend ac. Aliquam porttitor aliquet purus. Fusce condimentum eu sapien ut malesuada. Sed at nibh purus. Quisque et cursus nisl. Donec sed tincidunt ex.
</p>
<figure>
<img
src="https://dailybruin.com/images/2018/10/web.sp_.mwp_.nbk_.ADX_-640x461.jpg"
/>
<figcaption>
Freshman attacker Ashworth Molthen has registered 21 goals on the season, finding the back of the net in 13 of the 16 games so far this year for UCLA men’s water polo. UCLA is one of two teams remaining in the MPSF conference that remains undefeated.
(
Amy Dixon/Photo Editor
)
</figcaption>
</figure>
</article>
`;
31 changes: 31 additions & 0 deletions src/components/Article/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Article
route: /article
---

import { Playground, PropsTable } from 'docz'
import Article from '.'

# Article

An article's text and multimedia.

Note that `Article` expects an array of `Content`, which

<PropsTable of={Article} />

<Playground>
<Article content={[
{
type: 'text',
value:
'<strong>Lorem</strong> <a href="https://dailybruin.com">ipsum</a> dolor sit amet, consectetur adipiscing elit. Cras porttitor metus in pellentesque bibendum. Fusce rutrum sollicitudin finibus. Proin pellentesque leo enim, sed ultrices diam laoreet ut. Vivamus ut consequat nulla. Aenean sodales enim ut sapien rhoncus, in rhoncus metus mattis. Phasellus sed turpis tristique, tristique augue quis, lobortis est. Proin consectetur volutpat lacus, vitae luctus orci eleifend ac. Aliquam porttitor aliquet purus. Fusce condimentum eu sapien ut malesuada. Sed at nibh purus. Quisque et cursus nisl. Donec sed tincidunt ex.',
},
{
type: "image",
url: "https://dailybruin.com/images/2018/10/web.sp_.mwp_.nbk_.ADX_-640x461.jpg",
caption: "Freshman attacker Ashworth Molthen has registered 21 goals on the season, finding the back of the net in 13 of the 16 games so far this year for UCLA men’s water polo. UCLA is one of two teams remaining in the MPSF conference that remains undefeated.",
credit: "Amy Dixon/Photo Editor"
}
]} />
</Playground>
26 changes: 26 additions & 0 deletions src/components/Article/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react'
import { render, cleanup } from 'react-testing-library'
import Article from '.'

const content = [
{
type: 'text',
value:
'<strong>Lorem</strong> <a href="https://dailybruin.com">ipsum</a> dolor sit amet, consectetur adipiscing elit. Cras porttitor metus in pellentesque bibendum. Fusce rutrum sollicitudin finibus. Proin pellentesque leo enim, sed ultrices diam laoreet ut. Vivamus ut consequat nulla. Aenean sodales enim ut sapien rhoncus, in rhoncus metus mattis. Phasellus sed turpis tristique, tristique augue quis, lobortis est. Proin consectetur volutpat lacus, vitae luctus orci eleifend ac. Aliquam porttitor aliquet purus. Fusce condimentum eu sapien ut malesuada. Sed at nibh purus. Quisque et cursus nisl. Donec sed tincidunt ex.',
},
{
type: "image",
url: "https://dailybruin.com/images/2018/10/web.sp_.mwp_.nbk_.ADX_-640x461.jpg",
caption: "Freshman attacker Ashworth Molthen has registered 21 goals on the season, finding the back of the net in 13 of the 16 games so far this year for UCLA men’s water polo. UCLA is one of two teams remaining in the MPSF conference that remains undefeated.",
credit: "Amy Dixon/Photo Editor"
}
]

describe('Article', () => {
afterEach(cleanup)

it('Matches its snapshot', () => {
const { container } = render(<Article content={content} />)
expect(container.firstChild).toMatchSnapshot()
})
})
47 changes: 36 additions & 11 deletions src/components/Article/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
import * as React from 'react';
import { css } from 'react-emotion';
import * as React from 'react'
import Image, { ImageProps } from '../Image'

enum ContentType {
Text,
Photo,
Text = 'text',
Image = 'image',
}

interface Content {
type: Content;
content: string;
interface Text {
value: string
}

/**
* Article properties.
*/
interface ArticleProps {
/** The paragraphs of content for the story. */
content: Array<Content>;
dropcap: boolean;
content: any[]
dropcap: boolean
}

/** A footer to go at the bottom of every page. */
export default function Footer(props: ArticleProps) {
return <article>{}</article>;
export default class Article extends React.Component<ArticleProps> {
public static defaultProps = { dropcap: false }

public render() {
const renderedContent = this.props.content.map(
(content: any, i: number) => {
switch (content.type) {
case ContentType.Text:
const text = content as Text
return (
<p
key={i}
dangerouslySetInnerHTML={{
__html: text.value,
}}
/>
)
case ContentType.Image:
const image = content as ImageProps
return <Image {...image} />
default:
break
}
}
)

return <article>{renderedContent}</article>
}
}
20 changes: 20 additions & 0 deletions src/components/Image/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Image
route: /image
---

import { Playground, PropsTable } from 'docz'
import Image from '.'

# Image

An image with a caption.

<PropsTable of={Image} />

<Playground>
<Image url="http://dailybruin.com/images/2018/10/web.sp_.mwp_.nbk_.ADX_-640x461.jpg"
caption="Freshman attacker Ashworth Molthen has registered 21 goals on the season, finding the back of the net in 13 of the 16 games so far this year for UCLA men’s water polo. UCLA is one of two teams remaining in the MPSF conference that remains undefeated."
credit="Amy Dixon/Photo editor"
alt="Ashworth Molthen playing water polo." />
</Playground>
19 changes: 19 additions & 0 deletions src/components/Image/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react'

export interface ImageProps {
url: string
caption: string
credit: string
alt: string
}

export default function Image(props: ImageProps) {
return (
<figure>
<img src={props.url} alt={props.alt} />
<figcaption>
{props.caption} ({props.credit})
</figcaption>
</figure>
)
}
10 changes: 9 additions & 1 deletion src/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ In 1947, UC Berkeley provost Monroe E. Deutsch, [wrote the following](https://ww
The goal of Lux is to make this eternal vigilance easily accessible to all by compliing web best practices and commonly used news page components into an easy to use library.

Check out some of the components on the sidebar!
To use Lux, simply install it with your favorite package manager, e.g.:
```
yarn add @dailybruin/lux
```

Check out some of the components on the sidebar! To import a component, use the following syntax:
```javascript
import {Article} from '@dailybruin/lux'
```

0 comments on commit ea78c64

Please sign in to comment.