Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

docs: add quick start page #145

Merged
merged 8 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixes
- Fix docs pages presenting examples of wrong component @kuzhelov ([#124](https://github.com/stardust-ui/react/pull/124))
- Fix component variables when merging themes @levithomason ([#128](https://github.com/stardust-ui/react/pull/128))
- Fix Button styles when rendered as an anchor @levithomason ([#145](https://github.com/stardust-ui/react/pull/145))

### Features
- Add basic `Radio` component @alinais ([#100](https://github.com/stardust-ui/react/pull/100))
- Add `descriptionColor` to Header @kuzhelov ([#78](https://github.com/stardust-ui/react/pull/78))
- Add accessibility behavior description @kolaps33 ([#74](https://github.com/stardust-ui/react/pull/74))

### Documentation
- Add a Quick Start guide @levithomason ([#145](https://github.com/stardust-ui/react/pull/145))

<!--------------------------------[ v0.3.0 ]------------------------------- -->
## [v0.3.0](https://github.com/stardust-ui/react/tree/v0.3.0) (2018-08-22)
[Compare changes](https://github.com/stardust-ui/react/compare/v0.2.7...v0.3.0)
Expand Down
1 change: 1 addition & 0 deletions build/tsconfig.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"baseUrl": "../",
"paths": {
"@stardust-ui/react": ["src"],
"@stardust-ui/react/themes/teams": ["src/themes/teams"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"*": ["*", "types/*"]
},
"types": [
Expand Down
54 changes: 54 additions & 0 deletions docs/src/components/CodeSnippet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as React from 'react'
import Editor, { EDITOR_BACKGROUND_COLOR } from './Editor'

export interface ICodeSnippetProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is a point for further thought: to me it seems a bit unreasonable to use 'I' prefix for interface types - this leads to the fiolloiwng situation where interface types and alias type types - both with exactly the same semantics, - are mixed:

import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'

Here we are importing two type interfaces (in general sense) for styles and variables - but for some reason one uses I prefix :) What I would suggest is to omit I prefix altogether for all types - this will make them consistent. Actually, the same approach React has taken for its types - quite a few of them are TS interfaces, but all the exposed names are consistent to the client as there are no I prefixes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no opinion here other than it should follow the best practice. It is nice to know when you can use extends (interfaces but not types). However, it appears the official recommendation is to not use prefixes. Will update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went to update this and it appears we have 44 interfaces in 24 files prefixed with "I" and only 4 interfaces in 3 files that aren't. I think we should make a separate PR that addresses this and updates the team about the new standard.

I will still update my usage here to not include the prefix.

label?: string
mode?: 'jsx' | 'html' | 'sh'
value: string
style?: React.CSSProperties
}

const CodeSnippet = ({ label = '', value, mode, style, ...rest }: ICodeSnippetProps) => {
const editorMode: any = mode || label.replace(/.*\./, '') || 'jsx'
Copy link
Contributor

@kuzhelov kuzhelov Aug 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that we might obtain not supported editor mode's value here (like tsx from label). Is it fine to pass this value to AceEditor then, or we should opt to some default (maybe, 'text') mode, so that only explicitly supported modes will be rendered (and, thus, guaranteed to be rendered properly)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. This is partial left over from a previous iteration where label was named filename. However, the point still stands. I'm going to revert to using the less magical mode prop just as the Editor does. This will ensure we can explicitly set the mode/highlighting separate from the label in the code snippet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also asked if it is OK to pass an unsupported value, no. It will break the highlighting and also throw. Also, tsx is not a supported mode.


return (
<div
style={{
position: 'relative',
padding: '1rem',
marginBottom: '2rem',
background: EDITOR_BACKGROUND_COLOR,
...style,
}}
>
<div
style={{
position: 'absolute',
padding: '0.2rem 0.35rem',
top: '1rem',
right: '1rem',
lineHeight: 1,
color: '#899',
fontFamily: 'monospace',
fontSize: '0.8rem',
border: '1px solid #566',
zIndex: 100,
}}
>
{label || editorMode}
</div>
<Editor
id={btoa(value)}
highlightActiveLine={false}
highlightGutterLine={false}
mode={editorMode}
readOnly
showGutter={false}
showCursor={false}
value={editorMode === 'sh' ? value.replace(/^/g, '$ ') : value}
{...rest}
/>
</div>
)
}
export default CodeSnippet
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { withRouter, RouteComponentProps } from 'react-router'
import { renderToStaticMarkup } from 'react-dom/server'
import { html } from 'js-beautify'
import * as copyToClipboard from 'copy-to-clipboard'
import { Divider, Form, Grid, Menu, Segment, Visibility, SemanticCOLORS } from 'semantic-ui-react'
import { Divider, Form, Grid, Menu, Segment, Visibility } from 'semantic-ui-react'
import { Provider } from '@stardust-ui/react'

import {
Expand All @@ -17,7 +17,7 @@ import {
} from 'docs/src/utils'
import evalTypeScript from 'docs/src/utils/evalTypeScript'
import { callable, doesNodeContainClick, mergeThemes, pxToRem } from 'src/lib'
import Editor from 'docs/src/components/Editor'
import Editor, { EDITOR_BACKGROUND_COLOR, EDITOR_GUTTER_COLOR } from 'docs/src/components/Editor'
import ComponentControls from '../ComponentControls'
import ComponentExampleTitle from './ComponentExampleTitle'
import ContributionPrompt from '../ContributionPrompt'
Expand Down Expand Up @@ -49,9 +49,6 @@ interface IComponentExampleState {
copiedCode?: boolean
}

const EDITOR_BACKGROUND_COLOR = '#1D1F21'
const EDITOR_GUTTER_COLOR = '#26282d'

const childrenStyle: React.CSSProperties = {
paddingTop: 0,
maxWidth: pxToRem(500),
Expand Down
21 changes: 21 additions & 0 deletions docs/src/components/DocPage/DocPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react'
import DocumentTitle from 'react-document-title'
import { Header } from 'semantic-ui-react'

interface IDocPageProps {
title: string
description?: string
children: React.ReactNode
}

const DocPage = ({ title, description, children }: IDocPageProps) => (
<DocumentTitle title={'Stardust - ' + title}>
<div style={{ padding: '2rem', fontSize: '1.15rem', maxWidth: '80ch' }}>
<Header as="h1" content={title} subheader={description} textAlign="center" />

{children}
</div>
</DocumentTitle>
)

export default DocPage
1 change: 1 addition & 0 deletions docs/src/components/DocPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './DocPage'
12 changes: 8 additions & 4 deletions docs/src/components/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import * as _ from 'lodash'
import PropTypes from 'prop-types'
import * as React from 'react'
import AceEditor, { AceEditorProps } from 'react-ace'
import ace from 'brace'
import * as ace from 'brace'
import 'brace/ext/language_tools'
import 'brace/mode/jsx'
import 'brace/mode/html'
import 'brace/mode/jsx'
import 'brace/mode/sh'
import 'brace/theme/tomorrow_night'
import { eventStack, doesNodeContainClick } from 'src/lib'

Expand Down Expand Up @@ -41,14 +42,17 @@ languageTools.addCompleter(semanticUIReactCompleter)
export interface IEditorProps extends AceEditorProps {
id: string
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a DOM id and is required by AceEditor to work correctly.

value: string
mode?: 'html' | 'jsx'
mode?: 'html' | 'jsx' | 'sh'
onClick?: () => void
onOutsideClick?: (e: Event) => void
active?: boolean
showCursor?: boolean
highlightGutterLine?: boolean
}

export const EDITOR_BACKGROUND_COLOR = '#1D1F21'
export const EDITOR_GUTTER_COLOR = '#26282d'

class Editor extends React.Component<IEditorProps> {
private lineCount: number

Expand All @@ -57,7 +61,7 @@ class Editor extends React.Component<IEditorProps> {
public static propTypes = {
id: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
mode: PropTypes.oneOf(['html', 'jsx']),
mode: PropTypes.oneOf(['html', 'jsx', 'sh']),
onClick: PropTypes.func,
onOutsideClick: PropTypes.func,
active: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default, IEditorProps } from './Editor'
export { default, IEditorProps, EDITOR_BACKGROUND_COLOR, EDITOR_GUTTER_COLOR } from './Editor'
32 changes: 21 additions & 11 deletions docs/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,35 @@ class Sidebar extends React.Component<any, any> {
<Menu.Item>
<Logo spaced="right" size="mini" />
<strong>
Stardust &nbsp;
Stardust UI React &nbsp;
<small>
<em>{pkg.version}</em>
</small>
</strong>
<Menu.Menu>
<Menu.Item as="a" href={repoURL} target="_blank" rel="noopener noreferrer">
<Icon name="github" /> GitHub
</Menu.Item>
<Menu.Item
as="a"
href={`${repoURL}/blob/master/CHANGELOG.md`}
target="_blank"
rel="noopener noreferrer"
>
<Icon name="file alternate outline" /> CHANGELOG
</Menu.Item>
</Menu.Menu>
</Menu.Item>
<Menu.Item as={NavLink} exact to="/" activeClassName="active">
Introduction
</Menu.Item>
<Menu.Item as="a" href={repoURL} target="_blank" rel="noopener noreferrer">
<Icon name="github" /> GitHub
</Menu.Item>
<Menu.Item
as="a"
href={`${repoURL}/blob/master/CHANGELOG.md`}
target="_blank"
rel="noopener noreferrer"
>
<Icon name="file alternate outline" /> CHANGELOG
<Menu.Item>
Guides
<Menu.Menu>
<Menu.Item as={NavLink} exact to="/quick-start" activeClassName="active">
Quick Start
</Menu.Item>
</Menu.Menu>
</Menu.Item>
<Menu.Item active>
<SemanticUIInput
Expand Down
7 changes: 7 additions & 0 deletions docs/src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
margin: 1.5em 0;
}

blockquote {
border-left: 4px solid #777;
padding-left: 1rem;
margin-left: 0;
opacity: 0.8;
}

pre {
margin: 0;
}
Expand Down
2 changes: 2 additions & 0 deletions docs/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DocsRoot from './components/DocsRoot'

import Introduction from './views/Introduction'
import PageNotFound from './views/PageNotFound'
import QuickStart from './views/QuickStart'

const Router = () => (
<BrowserRouter basename={__BASENAME__}>
Expand All @@ -15,6 +16,7 @@ const Router = () => (
<Switch>
<DocsLayout exact path="/" component={Introduction} />
<DocsLayout exact path="/:type/:name" component={DocsRoot} sidebar />
<DocsLayout exact path="/quick-start" component={QuickStart} />
<DocsLayout exact path="/*" component={PageNotFound} />
</Switch>
</Switch>
Expand Down
10 changes: 9 additions & 1 deletion docs/src/views/Introduction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as _ from 'lodash'
import PropTypes from 'prop-types'
import * as React from 'react'
import { NavLink } from 'react-router-dom'

import Editor from 'docs/src/components/Editor'
import { Container, Divider, Grid, Header, Icon, Label, List, Segment } from 'semantic-ui-react'
Expand Down Expand Up @@ -38,14 +39,21 @@ Comparison.propTypes = {
}

const Introduction = () => (
<Container id="introduction-page">
<Container id="introduction-page" text>
<Segment basic textAlign="center">
<Logo centered size="small" />
<Header as="h1" textAlign="center">
{_.capitalize(pkg.name)}
<Header.Subheader>{pkg.description}</Header.Subheader>
</Header>
</Segment>
<p>
Stardust UI React is being built as an exemplar of the Stardust UI design language, component
specifications, and utilities.
</p>
<p>
See the <NavLink to="quick-start">Quick Start</NavLink> guide to get started.
</p>
</Container>
)

Expand Down
71 changes: 71 additions & 0 deletions docs/src/views/QuickStart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as React from 'react'
import { NavLink } from 'react-router-dom'
import { Header, Icon } from 'semantic-ui-react'

import { Button } from '@stardust-ui/react'

import CodeSnippet from '../components/CodeSnippet'
import DocPage from '../components/DocPage'

export default () => (
<DocPage title="Quick Start">
<Header as="h2">Install</Header>
<p>
Stardust UI should be installed as a <code>dependency</code> of your app.
</p>
<CodeSnippet mode="sh" value="yarn install @stardust-ui/react" />
<Header as="h2">Setup</Header>
<p>
Stardust components are styled using CSS in JS. This technique requires a style renderer to
render JavaScript objects to CSS.{' '}
<a href="https://reactjs.org/docs/context.html" target="_blank" rel="noopener nofollow">
React Context <Icon name="external" size="small" link fitted />
</a>{' '}
is used to provide the style renderer and theme to components.
</p>
<p>
Place a <code>{'<Provider />'}</code> at the root of your app and pass theme as props.
</p>
<CodeSnippet
label="index.jsx"
value={[
`import React from 'react'`,
`import ReactDOM from 'react-dom'`,
`import { Provider } from '@stardust-ui/react'`,
`import { fontFaces, staticStyles, theme } from '@stardust-ui/react/themes/teams'`,
``,
`import App from './App'`,
``,
`ReactDOM.render(`,
` <Provider theme={theme} staticStyles={staticStyles} fontFaces={fontFaces}>`,
` <App />`,
` </Provider>,`,
` document.getElementById('root'),`,
`)`,
].join('\n')}
/>
<Header as="h2">Usage</Header>
<p>That's it. You can now use Stardust UI components in your app.</p>
<CodeSnippet
label="App.jsx"
value={[
`import React from 'react'`,
`import { Button } from '@stardust-ui/react'`,
``,
`export default () => (`,
` <Button type="primary" content="Docs" icon="arrow right" iconPosition="after" />`,
`)`,
].join('\n')}
/>
<br />
{/* Show a preview of the above snippet */}
<Button
as={NavLink}
content="Docs"
type="primary"
icon="arrow right"
iconPosition="after"
to="components/button"
/>
</DocPage>
)
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as themes from './themes'
export { themes }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Export themes from our package.


export { default as Accordion } from './components/Accordion'
export { default as Button } from './components/Button'
export { default as Chat } from './components/Chat'
Expand Down
3 changes: 3 additions & 0 deletions src/themes/teams/components/Button/buttonStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const buttonStyles: IComponentPartStylesInput = {
(iconPosition
? {
display: 'inline-flex',
alignItems: 'center',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, there is a corresponding PR #135 where bunch of related Button problems are addressed.

As a next work item related to that - the PR with conformance tests that will ensure that shorthand prop names correspond to component's anatomy parts, so that it would be intuitive for client to decide which name should be used for styling specific component's part:

<Button icon={...} styles={ icon: () => ... } />

justifyContent: 'center',
}
: {
Expand Down Expand Up @@ -77,6 +78,7 @@ const buttonStyles: IComponentPartStylesInput = {
backgroundColor: typePrimaryBackgroundColor,
borderColor: typePrimaryBorderColor,
':hover': {
color: typePrimaryColor,
backgroundColor: typePrimaryBackgroundColorHover,
},
}),
Expand All @@ -86,6 +88,7 @@ const buttonStyles: IComponentPartStylesInput = {
backgroundColor: typeSecondaryBackgroundColor,
borderColor: typeSecondaryBorderColor,
':hover': {
color: typeSecondaryColor,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed button styles when rendering as an a tag.

borderColor: 'transparent',
backgroundColor: typeSecondaryBackgroundColorHover,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fontAwesomeIcons = new Map([
['arrow right', 'f061'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icon used in quick start example.

['chess rook', 'f447'],
['unordered list', 'f0ca'],
['ordered list', 'f0cb'],
Expand Down