-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from editor-js/ol-customisation
feat(OrderedList UI): support start property
- Loading branch information
Showing
15 changed files
with
246 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,8 @@ | |
{ | ||
type: 'List', | ||
data: { | ||
style: 'ordered', | ||
start: 2, | ||
items: [ | ||
{ | ||
content: "Canon", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { CheckListRenderer } from './ChecklistRenderer'; | ||
import { OrderedListRenderer } from './OrderedListRenderer'; | ||
import { UnorderedListRenderer } from './UnorderedListRenderer'; | ||
import { DefaultListCssClasses, CssPrefix } from './ListRenderer'; | ||
import { DefaultListCssClasses } from './ListRenderer'; | ||
|
||
export { CheckListRenderer, OrderedListRenderer, UnorderedListRenderer, DefaultListCssClasses, CssPrefix }; | ||
export { CheckListRenderer, OrderedListRenderer, UnorderedListRenderer, DefaultListCssClasses }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Default css prefix for list | ||
*/ | ||
export const CssPrefix = 'cdx-list'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.cdx-list-start-with-field { | ||
background: #F8F8F8; | ||
border: 1px solid rgba(226,226,229,0.20); | ||
border-radius: 6px; | ||
padding: 2px; | ||
display: grid; | ||
grid-template-columns: auto auto 1fr; | ||
grid-template-rows: auto; | ||
|
||
&__input { | ||
font-size: 14px; | ||
outline: none; | ||
font-weight: 500; | ||
font-family: inherit; | ||
border: 0; | ||
background: transparent; | ||
margin: 0; | ||
padding: 0; | ||
line-height: 22px; | ||
min-width: calc(100% - var(--toolbox-buttons-size) - var(--icon-margin-right)); | ||
|
||
&--invalid { | ||
background: red; | ||
} | ||
|
||
&::placeholder { | ||
color: var(--grayText); | ||
font-weight: 500; | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as Dom from '@editorjs/dom'; | ||
import { CssPrefix } from '../styles/CssPrefix'; | ||
|
||
/** | ||
* Options used in input rendering | ||
*/ | ||
interface InputOptions { | ||
/** | ||
* Placeholder, that will be displayed in input | ||
*/ | ||
placeholder: string; | ||
/** | ||
* Input will be rendered with this value inside | ||
*/ | ||
value?: string; | ||
/** | ||
* Html attributes, that would be added to the input element | ||
*/ | ||
attributes?: { | ||
[key: string]: string; | ||
}; | ||
} | ||
|
||
const css = { | ||
wrapper: `${CssPrefix}-start-with-field`, | ||
input: `${CssPrefix}-start-with-field__input`, | ||
inputInvalid: `${CssPrefix}-start-with-field__input--invalid`, | ||
}; | ||
|
||
/** | ||
* Method that renders html element for popover start with item | ||
* @param inputCallback - callback method that could change nested list attributes on input | ||
* @param inputOptions - options used in input rendering | ||
* @param inputOptions.value - input will be rendered with this value inside | ||
* @param inputOptions.placeholder - placeholder, that will be displayed in input | ||
* @param inputOptions.attributes - html attributes, that would be added to the input element | ||
* @returns - rendered html element | ||
*/ | ||
export function renderToolboxInput(inputCallback: (index: number) => void, | ||
{ value, placeholder, attributes }: InputOptions): HTMLElement { | ||
const startWithElementWrapper = Dom.make('div', css.wrapper); | ||
|
||
const input = Dom.make('input', css.input, { | ||
placeholder, | ||
/** | ||
* Used to prevent focusing on the input by Tab key | ||
* (Popover in the Toolbar lays below the blocks, | ||
* so Tab in the last block will focus this hidden input if this property is not set) | ||
*/ | ||
tabIndex: -1, | ||
/** | ||
* Value of the start property, if it is not specified, then it is set to one | ||
*/ | ||
value, | ||
}) as HTMLInputElement; | ||
|
||
/** | ||
* Add passed attributes to the input | ||
*/ | ||
for (const attribute in attributes) { | ||
input.setAttribute(attribute, attributes[attribute]); | ||
} | ||
|
||
startWithElementWrapper.appendChild(input); | ||
|
||
input.addEventListener('input', () => { | ||
const validInput = input.checkValidity(); | ||
|
||
/** | ||
* If input is invalid and classlist does not contain invalid class, add it | ||
*/ | ||
if (!validInput && !input.classList.contains(css.inputInvalid)) { | ||
input.classList.add(css.inputInvalid); | ||
} | ||
|
||
/** | ||
* If input is valid and classlist contains invalid class, remove it | ||
*/ | ||
if (validInput && input.classList.contains(css.inputInvalid)) { | ||
input.classList.remove(css.inputInvalid); | ||
} | ||
|
||
/** | ||
* If input is invalid, than do not change start with attribute | ||
*/ | ||
if (!validInput) { | ||
return; | ||
} | ||
|
||
inputCallback(Number(input.value)); | ||
}); | ||
|
||
return startWithElementWrapper; | ||
} |
Oops, something went wrong.