Skip to content

Instantly share code, notes, and snippets.

@MattyBalaam
Created May 14, 2020 06:14
Show Gist options
  • Save MattyBalaam/8aa769c8f02be314f92d71a4e27ea999 to your computer and use it in GitHub Desktop.
Save MattyBalaam/8aa769c8f02be314f92d71a4e27ea999 to your computer and use it in GitHub Desktop.
.public-DraftStyleDefault-ltr {
.justify-left & {
text-align: left;
}
.justify-right & {
text-align: right;
}
.justify-center & {
text-align: center;
}
.justify-full & {
text-align: justify;
}
}
import React, { PureComponent } from 'react';
import { createBlockStyleButton } from 'draft-js-buttons';
import TextAlignmentButton from './TextAlignmentButton';
import { TYPES } from 'textAlignment';
export default class Alignment extends PureComponent {
buttons = TYPES.map((type) => {
const Button = createBlockStyleButton({
blockType: type,
key: type,
children: <TextAlignmentButton type={ type } />,
});
return Button;
});
render() {
return this.buttons.map(Button => <Button { ...this.props } />);
}
}
import './textAlignment.css';
export const TYPES = ['justify-left', 'justify-right', 'justify-center', 'justify-full'];
export default () => ({
blockStyleFn: (contentBlock) => {
const type = contentBlock.getType();
return TYPES.includes(type) && type;
},
});
import React, { PureComponent } from 'react';
export default class Alignment extends PureComponent {
render() {
return (
<div>
<svg xmlns="http://www.w3.org/2000/svg" width="11" height="14" viewBox="0 0 11 14">
<g fillRule="evenodd">
<rect width="12" height="2" x="0" y="2" rx="1" />
<rect width="12" height="2" x="0" y="6" rx="1" />
<rect width="12" height="2" x="0" y="10" rx="1" />
</g>
</svg>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment