-
Notifications
You must be signed in to change notification settings - Fork 3
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 #336 from virtualidentityag/develop
Merge develop
- Loading branch information
Showing
50 changed files
with
1,830 additions
and
90 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
/.vite/ | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
|
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
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,65 @@ | ||
/* eslint-disable react/no-children-prop */ | ||
import clsx from 'clsx'; | ||
import { EditorState, RichUtils } from 'draft-js'; | ||
import React, { MouseEvent, ReactNode, useCallback, useMemo } from 'react'; | ||
import { DraftJsStyleButtonProps } from '@draft-js-plugins/buttons'; | ||
import { Button } from 'antd'; | ||
import { ButtonType } from 'antd/lib/button/button'; | ||
|
||
interface ButtonProps extends DraftJsStyleButtonProps { | ||
type: ButtonType; | ||
} | ||
|
||
interface CreateBlockStyleButtonProps extends Omit<DraftJsStyleButtonProps, 'buttonProps'> { | ||
blockType: string; | ||
children: ReactNode; | ||
editorState: EditorState; | ||
buttonProps?: ButtonProps; | ||
} | ||
|
||
const BlockStyleButton = ({ | ||
blockType, | ||
children, | ||
theme, | ||
buttonProps, | ||
setEditorState, | ||
editorState, | ||
}: CreateBlockStyleButtonProps) => { | ||
const toggleStyle = useCallback( | ||
(event: MouseEvent): void => { | ||
event.preventDefault(); | ||
setEditorState(RichUtils.toggleBlockType(editorState, blockType)); | ||
}, | ||
[editorState, setEditorState], | ||
); | ||
|
||
const preventBubblingUp = useCallback((event: MouseEvent): void => { | ||
event.preventDefault(); | ||
}, []); | ||
|
||
const blockTypeIsActive = useMemo((): boolean => { | ||
// if the button is rendered before the editor | ||
if (!editorState) { | ||
return false; | ||
} | ||
|
||
const type = editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getStartKey()).getType(); | ||
return type === blockType; | ||
}, [editorState]); | ||
|
||
const className = blockTypeIsActive ? clsx(theme.button, theme.active) : theme.button; | ||
|
||
return ( | ||
<Button | ||
children={children} | ||
className={className} | ||
onMouseDown={preventBubblingUp} | ||
onClick={toggleStyle} | ||
size="small" | ||
role="button" | ||
aria-label={`create ${blockType}`} | ||
{...buttonProps} | ||
/> | ||
); | ||
}; | ||
export default BlockStyleButton; |
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,59 @@ | ||
/* eslint-disable react/no-children-prop */ | ||
import clsx from 'clsx'; | ||
import { EditorState, RichUtils } from 'draft-js'; | ||
import React, { MouseEvent, ReactNode, useCallback, useMemo } from 'react'; | ||
import { DraftJsStyleButtonProps } from '@draft-js-plugins/buttons'; | ||
import { Button } from 'antd'; | ||
import { ButtonType } from 'antd/lib/button/button'; | ||
|
||
interface ButtonProps extends DraftJsStyleButtonProps { | ||
type: ButtonType; | ||
} | ||
|
||
interface CreateInlineStyleButtonProps extends Omit<DraftJsStyleButtonProps, 'buttonProps'> { | ||
inlineStyle: string; | ||
children: ReactNode; | ||
editorState: EditorState; | ||
buttonProps?: ButtonProps; | ||
} | ||
|
||
const InlineStyleButton = ({ | ||
inlineStyle, | ||
children, | ||
theme, | ||
buttonProps, | ||
setEditorState, | ||
editorState, | ||
}: CreateInlineStyleButtonProps) => { | ||
const toggleStyle = useCallback( | ||
(event: MouseEvent): void => { | ||
event.preventDefault(); | ||
setEditorState(RichUtils.toggleInlineStyle(editorState, inlineStyle)); | ||
}, | ||
[editorState, setEditorState], | ||
); | ||
|
||
const preventBubblingUp = useCallback((event: MouseEvent): void => { | ||
event.preventDefault(); | ||
}, []); | ||
|
||
const styleIsActive = useMemo((): boolean => { | ||
return editorState && editorState.getCurrentInlineStyle().has(inlineStyle); | ||
}, [editorState]); | ||
|
||
const className = styleIsActive ? clsx(theme.button, theme.active) : theme.button; | ||
|
||
return ( | ||
<Button | ||
children={children} | ||
className={className} | ||
onMouseDown={preventBubblingUp} | ||
onClick={toggleStyle} | ||
size="small" | ||
role="button" | ||
aria-label={`${inlineStyle} text`} | ||
{...buttonProps} | ||
/> | ||
); | ||
}; | ||
export default InlineStyleButton; |
Oops, something went wrong.