Skip to content

Fixes #36 - custom inline styles#97

Merged
thibaudcolas merged 13 commits intomasterfrom
feature/custom-inline-styles
Oct 17, 2017
Merged

Fixes #36 - custom inline styles#97
thibaudcolas merged 13 commits intomasterfrom
feature/custom-inline-styles

Conversation

@vincentaudebert
Copy link
Copy Markdown
Contributor

@vincentaudebert vincentaudebert commented Aug 30, 2017

Fixes #36. For your review @thibaudcolas

Added a new draftUtils function and tested it with some edge cases + 100% coverage.

Let me know what you think.

@thibaudcolas
Copy link
Copy Markdown
Member

Thank you @vincentaudebert 👏 ! Looks good from afar, I'll do a proper review next week.

Comment thread lib/api/DraftUtils.js Outdated
parseCustomStyleMap(constantInlineStyles, defaultCustomStyleMap, inlineStyles) {
const customStyleMap = defaultCustomStyleMap;
const styleValues = Object.keys(constantInlineStyles).map(k => constantInlineStyles[k]);
const verifiedStyles = inlineStyles.filter(style => styleValues.indexOf(style.type) !== -1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems problematic. If the type isn't in constantInlineStyles, it's not going to be in verifiedStyles and won't be added to the style map, making it impossible to define styles for custom inline styles.

Comment thread lib/api/constants.js Outdated
export const CUSTOM_STYLE_MAP = {
[INLINE_STYLE.MARK]: {
backgroundColor: 'yellow',
color: 'black',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will remove the color override – I think it would be better if we retained the normal text color.

Comment thread lib/api/constants.js
marginLeft: '1em',
marginTop: '1em',
marginBottom: '1em',
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like the styles of a blockquote. Here we should target inline styles only, so this should be the q element: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q.

Comment thread lib/components/DraftailEditor.js Outdated
maxListNesting: 1,
// Frequency at which the save callback is triggered (ms).
stateSaveInterval: 250,
customStyleMap: {},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a leftover from a previous iteration.

Comment thread lib/components/DraftailEditor.js Outdated
type: PropTypes.string.isRequired,
// Represents the inline style in the editor UI.
icon: PropTypes.string,
style: PropTypes.Object,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Every single one of these props must be commented so we can add those comments in the README as documentation.

Comment thread lib/components/DraftailEditor.js Outdated
component: type.decorator,
}));

const customStyleMapParsed = DraftUtils.parseCustomStyleMap(INLINE_STYLE, CUSTOM_STYLE_MAP, inlineStyles);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wouldn't it be simpler if this was directly done in render, instead of being added to the state? Here this will fall out of date if the editor is re-rendered with new values for inlineStyles.

@thibaudcolas thibaudcolas dismissed their stale review October 17, 2017 07:35

Refactorings

@thibaudcolas thibaudcolas force-pushed the feature/custom-inline-styles branch 2 times, most recently from 1e08cfe to 79810c3 Compare October 17, 2017 10:48
Comment thread README.md

- Block types: `H1`, `H2`, `H3`, `H4`, `H5`, `H6`, `Blockquote`, `Code`, `UL`, `OL`, `P`
- Inline styles: `Bold`, `Italic`, `Underline`, `Monospace`, `Strikethrough`
- Inline styles: `Bold`, `Italic`, `Code`, `Underline`, `Strikethrough`, `Mark`, `Keyboard`, `Superscript`, `Subscript`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are more, but I chose to leave them out because they are seldom used in rich text editors.

Comment thread README.md

Simple blocks are very easy to create. Add a new block type to `blockTypes`, specifying which `element` and `className` to display the block as.

Here is an example, creating a "Terms & conditions" block:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not my fav example but I hope it's easy enough to relate to the need for this.

Comment thread README.md
#### Custom inline styles

Custom inline styles aren't supported at the moment. This is on the roadmap, please refer to [#36](https://github.com/springload/draftail/issues/36).
Custom inline styles only require a `style` prop, defining which CSS properties to apply when the format is active.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not actually required – but if it's not there, there will be no way to tell whether the styles are active or not.

@thibaudcolas thibaudcolas merged commit 16e2940 into master Oct 17, 2017
@thibaudcolas thibaudcolas deleted the feature/custom-inline-styles branch October 17, 2017 11:02
@thibaudcolas thibaudcolas added this to the v1.0.0 milestone Oct 17, 2017
@thibaudcolas thibaudcolas modified the milestones: v1.0.0, Wagtail 2.0 Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants