-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More code duplication reduction (#161)
- Loading branch information
1 parent
002fda1
commit a171f9c
Showing
8 changed files
with
317 additions
and
320 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { BaseSectionItem, BaseSectionContent } from '../baseSection'; | ||
|
||
interface SectionEditFormProps<T extends BaseSectionItem> { | ||
readonly content: BaseSectionContent<T>; | ||
readonly setContent: React.Dispatch<React.SetStateAction<BaseSectionContent<T>>>; | ||
readonly renderItemEdit: (item: T, index: number) => React.ReactNode; | ||
readonly addItem: () => void; | ||
readonly removeItem: (index: number) => void; | ||
} | ||
|
||
export function SectionEditForm<T extends BaseSectionItem>({ | ||
content, | ||
setContent, | ||
renderItemEdit, | ||
addItem, | ||
removeItem | ||
}: Readonly<SectionEditFormProps<T>>) { | ||
return ( | ||
<div className={`${content.constructor.name.toLowerCase()}-items-edit`}> | ||
{content.items.map((item, index) => ( | ||
<div key={item.id} className={`${content.constructor.name.toLowerCase()}-item-edit`}> | ||
{renderItemEdit(item, index)} | ||
<button onClick={() => removeItem(index)}> | ||
<FormattedMessage id={`sectionObject.removeItem`} /> | ||
</button> | ||
</div> | ||
))} | ||
<button onClick={addItem}> | ||
<FormattedMessage id={`sectionObject.addItem`} /> | ||
</button> | ||
<div className="show-zeros-toggle"> | ||
<label> | ||
<input | ||
type="checkbox" | ||
checked={content.showEmpty} | ||
onChange={() => setContent({ ...content, showEmpty: !content.showEmpty })} | ||
/> | ||
<FormattedMessage id={`sectionObject.showEmpty`} /> | ||
</label> | ||
</div> | ||
</div> | ||
); | ||
} |
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,24 @@ | ||
import React from 'react'; | ||
import { FaInfoCircle } from 'react-icons/fa'; | ||
import { Tooltip } from 'react-tooltip'; | ||
import { BaseSectionItem } from '../baseSection'; | ||
|
||
interface SectionItemProps<T extends BaseSectionItem> { | ||
readonly item: T; | ||
readonly renderContent: (item: T) => React.ReactNode; | ||
} | ||
|
||
export function SectionItem<T extends BaseSectionItem>({ item, renderContent }: Readonly<SectionItemProps<T>>) { | ||
return ( | ||
<div className={`section-item ${item.constructor.name.toLowerCase()}-item`}> | ||
<span>{item.name}</span> | ||
{renderContent(item)} | ||
<FaInfoCircle | ||
className="info-icon" | ||
data-tooltip-content={item.description} | ||
data-tooltip-id={`description-tooltip-${item.id}`} | ||
/> | ||
<Tooltip id={`description-tooltip-${item.id}`} place="top" /> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.