Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

adding dialog and docs #133

Merged
merged 2 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions docs/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ export default [
materialDocsLink:
'https://material.io/design/components/selection-controls.html#radio-buttons',
},
{
name: 'Dialog',
url: 'dialog',
componentKey: 'dialog',
editorHeight: '500px',
description:
'Dialogs inform users about a task or decision that needs to be made.',
component: 'src/components/component-doc',
materialDocsLink: 'https://material.io/design/components/dialogs.html',
},
];
22 changes: 22 additions & 0 deletions docs/examples/dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class DialogExample extends Component {
render() {
return (
<Dialog style={{ maxWidth: '500px' }}>
<Dialog.Title>Dialog Title</Dialog.Title>
<Dialog.Body>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam
consequatur enim voluptates nobis perferendis voluptatibus alias
modi voluptate dolorum ipsa amet.
</p>
</Dialog.Body>
<Dialog.Actions>
<Button flat>Cancel</Button>
<Button flat>Accept</Button>
</Dialog.Actions>
</Dialog>
);
}
}

return <DialogExample />;
27 changes: 27 additions & 0 deletions docs/readmes/dialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Usage

```jsx
import { Dialog } from 'materialish';
import 'materialish/dialog.css';
```

Take note of the fact that a dialog is made up of several components. To see how they
are used together, refer to the example above.

## Props

All of the components of a dialog receive the same props.

| Prop Name | Default Value | Required | Description |
| --------- | ------------- | -------- | ------------------------------------------------------------------ |
| className | | No | Additional class name(s) to add to the dialog component |
| ...rest | | No | Other props are placed on the root element of the dialog component |

## CSS Variables

These CSS variables should be applied to the `<Dialog/>` component, and not the sub-components.

| Variable | Default Value | Description |
| ----------------- | ------------- | ------------------------------------------------------ |
| --mt-baseFontSize | 1rem | The text size of the dialog is based off of this value |
| --mt-fontFamily | 'Roboto' | The font family to use for text |
5 changes: 5 additions & 0 deletions docs/src/components/component-doc.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@
align-items: center;
justify-content: center;
min-height: 150px;
padding: 50px;
background-color: #f2f2f2;
border-radius: 5px 5px 0 0;
margin-top: 50px;
}

.componentDoc_editor .CodeMirror {
min-height: var(--editorHeight, 300px);
}
4 changes: 4 additions & 0 deletions docs/src/components/component-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class ComponentDoc extends Component {
componentKey,
sourceLink,
materialDocsLink,
editorHeight = '300px',
} = component;

const sourceLinkToUse = sourceLink
Expand Down Expand Up @@ -74,6 +75,9 @@ export class ComponentDoc extends Component {
your changes.
</div>
<Editor
style={{
'--editorHeight': editorHeight,
}}
className="componentDoc_editor"
theme="oceanic-next"
codeText={code}
Expand Down
20 changes: 10 additions & 10 deletions docs/src/vendor/doc-components/editor/editor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import PropTypes from "prop-types";
import React from 'react';
import PropTypes from 'prop-types';

let CodeMirror;
if (typeof document !== 'undefined') {
Expand All @@ -14,15 +14,15 @@ class Editor extends React.Component {
onChange: PropTypes.func,
readOnly: PropTypes.bool,
tabSize: PropTypes.number,
theme: PropTypes.string
theme: PropTypes.string,
};

static defaultProps = {
className: "",
className: '',
lineNumbers: false,
readOnly: false,
tabSize: 2,
theme: "oceanic-next"
theme: 'oceanic-next',
};

componentDidMount() {
Expand All @@ -31,16 +31,16 @@ class Editor extends React.Component {
}

this.editor = CodeMirror.fromTextArea(this.refs.editor, {
mode: "javascript",
mode: 'javascript',
lineNumbers: this.props.lineNumbers,
smartIndent: false,
tabSize: this.props.tabSize,
matchBrackets: true,
theme: this.props.theme,
readOnly: this.props.readOnly
readOnly: this.props.readOnly,
});

this.editor.on("change", this.handleChange);
this.editor.on('change', this.handleChange);
}

componentDidUpdate() {
Expand All @@ -61,10 +61,10 @@ class Editor extends React.Component {
}

render() {
const { className } = this.props;
const { className, style } = this.props;

return (
<div className={className}>
<div className={className} style={style}>
<textarea ref="editor" defaultValue={this.props.codeText} />
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions docs/static.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const readmes = {
icons: fs.readFileSync('./readmes/icons.md', { encoding: 'utf-8' }),
spinner: fs.readFileSync('./readmes/spinner.md', { encoding: 'utf-8' }),
radio: fs.readFileSync('./readmes/radio.md', { encoding: 'utf-8' }),
dialog: fs.readFileSync('./readmes/dialog.md', { encoding: 'utf-8' }),
};

const examples = {
Expand All @@ -25,6 +26,7 @@ const examples = {
icons: fs.readFileSync('./examples/icons.js', { encoding: 'utf-8' }),
spinner: fs.readFileSync('./examples/spinner.js', { encoding: 'utf-8' }),
radio: fs.readFileSync('./examples/radio.js', { encoding: 'utf-8' }),
dialog: fs.readFileSync('./examples/dialog.js', { encoding: 'utf-8' }),
};

// import { addSearchObjects } from './algolia'
Expand Down
30 changes: 30 additions & 0 deletions src/dialog/dialog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.mt-dialog {
font-family: var(--mt-fontFamily, 'Roboto');
font-size: var(--mt-baseFontSize, 1rem);
background-color: #fff;
text-align: left;
box-shadow: 0 11px 15px -7px rgba(0, 0, 0, 0.2), 0 24px 38px 3px rgba(0, 0, 0, 0.14), 0 9px 46px 8px rgba(0, 0, 0, 0.12);
border-radius: 0.125em;
}

.mt-dialog_title {
color: #212121;
font-size: 1.25em;
padding: 1.2em 1.2em 0;
font-weight: 500;
}

.mt-dialog_content {
color: #757575;
margin: 1.25em 1.5em 1.5em;
}

.mt-dialog_actions {
padding: 0.5em;
display: flex;
justify-content: flex-end;
}

.mt-dialog_actions .mt-button+.mt-button {
margin-left: 0.43em;
}
26 changes: 26 additions & 0 deletions src/dialog/dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

class Dialog extends Component {
static Title = ({ className = '', ...props }) => (
<div className={`mt-dialog_title ${className}`} {...props} />
);
static Body = ({ className = '', ...props }) => (
<div className={`mt-dialog_content ${className}`} {...props} />
);

static Actions = ({ className = '', ...props }) => (
<div className={`mt-dialog_actions ${className}`} {...props} />
);

render() {
const { className = '', ...props } = this.props;
return <div className={`mt-dialog ${className}`} {...props} />;
}
}

Dialog.propTypes = {
className: PropTypes.string,
};

export default Dialog;
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import Switch from './switch/switch';
import Avatar from './avatar/avatar';
import Spinner from './spinner/spinner';
import Radio from './radio/radio';
import Dialog from './dialog/dialog';

export { Avatar, Button, Checkbox, Ripple, Spinner, Switch, Radio };
export { Avatar, Button, Checkbox, Dialog, Ripple, Spinner, Switch, Radio };
30 changes: 30 additions & 0 deletions stories/dialog.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { setOptions } from '@storybook/addon-options';
import '../src/dialog/dialog.css';
import { Dialog } from '../src/index';
import { Button } from '../src/index';

setOptions({
name: 'Materialish',
addonPanelInRight: true,
});

storiesOf('Dialog', module).add('Regular', () => (
<Dialog>
<Dialog.Title>I am a modal</Dialog.Title>
<Dialog.Body>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam
consequatur enim voluptates nobis perferendis voluptatibus alias modi
voluptate dolorum ipsa amet, aliquam similique blanditiis iusto ipsam,
atque beatae aliquid sit! Lorem ipsum dolor sit amet consectetur
adipisicing elit.
</p>
</Dialog.Body>
<Dialog.Actions>
<Button flat>Nevermind</Button>
<Button flat>Accept</Button>
</Dialog.Actions>
</Dialog>
));