Skip to content

Commit

Permalink
Merge pull request #33 from niuware/development
Browse files Browse the repository at this point in the history
Rewrite from class to function component
  • Loading branch information
niuware authored Oct 10, 2019
2 parents 0f5d8b3 + b86c37b commit fe4a3f5
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 373 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ $ npm run serve

## Future plans

- Code refactor
- Add new features
- Increase test coverage

## Suggestions and issues
Expand Down
5 changes: 5 additions & 0 deletions examples/custom-inline-toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import React from 'react'
import MUIRichTextEditor from '../../'
import InvertColorsIcon from '@material-ui/icons/InvertColors'

const save = (data: string) => {
console.log(data)
}

const CustomInlineToolbar = () => {
return (
<MUIRichTextEditor
label="Try selecting some text to show the inline toolbar..."
inlineToolbar={true}
inlineToolbarControls={["bold", "italic", "my-style", "link"]}
onSave={save}
customControls={[
{
name: "my-style",
Expand Down
55 changes: 25 additions & 30 deletions examples/ref-save/index.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
import React from 'react'
import React, { FunctionComponent, useRef, Ref, MutableRefObject } from 'react'
import MUIRichTextEditor from '../../'

class RefSave extends React.Component {
private ref: any
constructor(props: any) {
super(props)
this.ref = React.createRef()
}
const RefSave: FunctionComponent = (props) => {

const ref = useRef()

handleClick = () => {
this.ref.current.save()
const handleClick = () => {
(ref as any).current.save()
}

handleSave = (data: string) => {
const handleSave = (data: string) => {
console.log(data)
}

render() {
return (
<div>
Save editor state from external button:
<button style={{
marginLeft: 5,
padding: 5
}}
onClick={this.handleClick}>
Save
</button>
<MUIRichTextEditor
label="Type something here..."
onSave={this.handleSave}
ref={this.ref}
controls={["bold", "italic", "underline", "quote", "clear"]}
/>
</div>
)
}
return (
<div>
Save editor state from external button:
<button style={{
marginLeft: 5,
padding: 5
}}
onClick={handleClick}>
Save
</button>
<MUIRichTextEditor
label="Type something here..."
onSave={handleSave}
ref={ref}
controls={["bold", "italic", "underline", "quote", "clear"]}
/>
</div>
)
}

export default RefSave
16 changes: 13 additions & 3 deletions examples/theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@ import React from 'react'
import { createMuiTheme, Theme, MuiThemeProvider } from '@material-ui/core/styles'
import MUIRichTextEditor from '../../'

export const defaultTheme: Theme = createMuiTheme()
export const defaultTheme: Theme = createMuiTheme({
palette: {
primary: {
main: "#000000"
}
}
})

Object.assign(defaultTheme, {
overrides: {
MUIRichTextEditor: {
root: {
backgroundColor: "#ebebeb",
},
container: {
display: "flex",
flexDirection: "column-reverse"
},
editor: {
borderBottom: "1px solid gray",
backgroundColor: "#ebebeb",
padding: "0 20px"
},
toolbar: {
borderTop: "1px solid gray",
backgroundColor: "#ebebeb"
},
placeHolder: {
backgroundColor: "#ebebeb",
paddingLeft: "20px",
paddingLeft: 20,
width: "inherit"
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {default} from './src/MUIRichTextEditor'
export {default} from './src/MUIRichTextEditor'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mui-rte",
"version": "1.4.0",
"version": "1.5.0",
"description": "Material-UI Rich Text Editor and Viewer",
"keywords": [
"material-ui",
Expand Down
Loading

0 comments on commit fe4a3f5

Please sign in to comment.