forked from globalfund/data-explorer-client
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #148 from zimmerman-team/feat/base-report
Feat/base report DX-1420
- Loading branch information
Showing
32 changed files
with
689 additions
and
327 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
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
127 changes: 127 additions & 0 deletions
127
src/app/modules/common/RichEditor/FontSizeController/index.tsx
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,127 @@ | ||
import { EditorState, RichUtils, ContentState, Modifier } from "draft-js"; | ||
import { set } from "lodash"; | ||
import React, { useEffect } from "react"; | ||
|
||
interface Props { | ||
getEditorState: () => EditorState; | ||
setEditorState: (value: EditorState) => void; | ||
theme: any; | ||
} | ||
export default function FontSizeController(props: Props) { | ||
const [fontSize, setFontSize] = React.useState(10); | ||
|
||
const reduceFontSize = () => { | ||
const editorState = props.getEditorState(); | ||
|
||
const currentStyle = editorState.getCurrentInlineStyle(); | ||
|
||
let newEditorState = editorState; | ||
if (currentStyle.has(`font-size-${fontSize - 1}`)) { | ||
newEditorState = RichUtils.toggleInlineStyle( | ||
editorState, | ||
`font-size-${fontSize - 1}` | ||
); // reset the font size | ||
} | ||
|
||
props.setEditorState( | ||
RichUtils.toggleInlineStyle(newEditorState, `font-size-${fontSize - 1}`) | ||
); | ||
setFontSize((prev) => prev - 1); | ||
}; | ||
const increaseFontSize = () => { | ||
const editorState = props.getEditorState(); | ||
const currentStyle = editorState.getCurrentInlineStyle(); | ||
let newEditorState = editorState; | ||
|
||
if (currentStyle.has(`font-size-${fontSize + 1}`)) { | ||
// reset the font size | ||
newEditorState = RichUtils.toggleInlineStyle( | ||
editorState, | ||
`font-size-${fontSize + 1}` | ||
); | ||
} | ||
props.setEditorState( | ||
RichUtils.toggleInlineStyle(newEditorState, `font-size-${fontSize + 1}`) | ||
); | ||
setFontSize((prev) => prev + 1); | ||
}; | ||
|
||
useEffect(() => { | ||
const currentStyle = props.getEditorState().getCurrentInlineStyle(); | ||
const nfontSize = currentStyle.findLast((style: any) => | ||
style.includes("font-size") | ||
); | ||
if (nfontSize) { | ||
const size = nfontSize.split("-")[2]; | ||
setFontSize(Number(size)); | ||
} | ||
}, [props.getEditorState().getCurrentInlineStyle()]); | ||
|
||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
if (e.target.value === "" || /^[0-9\b]+$/.test(e.target.value)) { | ||
const editorState = props.getEditorState(); | ||
const currentStyle = editorState.getCurrentInlineStyle(); | ||
let newEditorState = editorState; | ||
|
||
if (currentStyle.has(`font-size-${e.target.value}`)) { | ||
// reset the font size | ||
newEditorState = RichUtils.toggleInlineStyle( | ||
editorState, | ||
`font-size-${e.target.value}` | ||
); | ||
} | ||
props.setEditorState( | ||
RichUtils.toggleInlineStyle( | ||
newEditorState, | ||
`font-size-${e.target.value}` | ||
) | ||
); | ||
setFontSize(Number(e.target.value)); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div | ||
css={` | ||
width: 57px; | ||
height: 24px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
border-radius: 8px; | ||
background: #f4f4f4; | ||
span { | ||
font-size: 14px; | ||
color: #70777e; | ||
font-family: "GothamNarrow-Bold", sans-serif; | ||
cursor: pointer; | ||
} | ||
input { | ||
width: 20px; | ||
height: 100%; | ||
text-align: center; | ||
background: transparent; | ||
border: none; | ||
font-size: 14px; | ||
font-family: "GothamNarrow-Bold", sans-serif; | ||
color: #70777e; | ||
outline: none; | ||
} | ||
`} | ||
> | ||
<span onClick={() => reduceFontSize()}>-</span> | ||
<input | ||
type="text" | ||
name="font-size" | ||
id="" | ||
onChange={handleInputChange} | ||
value={fontSize} | ||
min={1} | ||
/> | ||
<span onClick={() => increaseFontSize()}>+</span> | ||
</div> | ||
</> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/app/modules/common/RichEditor/FontSizeController/styleMap.ts
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,11 @@ | ||
const fontSizeStyleMap = { | ||
"font-size-1": { fontSize: "1px" }, | ||
}; | ||
|
||
for (let i = 1; i <= 100; i++) { | ||
fontSizeStyleMap[`font-size-${i}` as keyof typeof fontSizeStyleMap] = { | ||
fontSize: `${i}px`, | ||
}; | ||
} | ||
|
||
export default fontSizeStyleMap; |
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
Oops, something went wrong.