-
Notifications
You must be signed in to change notification settings - Fork 39
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 #462 from oddbit/issue/459-editing-article-meta-data
feat: editing article meta data
- Loading branch information
Showing
8 changed files
with
417 additions
and
185 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,27 @@ | ||
interface BadgeProps { | ||
title: string; | ||
className?: string; | ||
disabled?: boolean; | ||
onRemove?: () => void; | ||
} | ||
|
||
export function Badge(props: BadgeProps) { | ||
const {title, className, disabled, onRemove} = props; | ||
|
||
let badgeClassName = "border px-3 py-1 text-xs font-semibold rounded-full"; | ||
badgeClassName = className ? badgeClassName.concat(` ${className}`) : badgeClassName; | ||
|
||
return ( | ||
<div className={badgeClassName}> | ||
<div className="relative w-full inline-flex items-center justify-between"> | ||
<span>{title}</span> | ||
|
||
{onRemove && ( | ||
<button disabled={disabled} onClick={onRemove} aria-label="Remove badge" className="ml-2"> | ||
<span className="relative top-[2px] i-ic-close" /> | ||
</button> | ||
)} | ||
</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,61 @@ | ||
import {useState} from "react"; | ||
import {Badge} from "../Badge"; | ||
import {Button} from "./../Button"; | ||
import {Input} from "./Input"; | ||
|
||
interface MultipleTextProps { | ||
title?: string; | ||
placeholder?: string; | ||
loading?: boolean; | ||
disabled?: boolean; | ||
value?: string[]; | ||
onChange?: (value: string[]) => void; | ||
} | ||
|
||
export function MultipleText(props: MultipleTextProps) { | ||
const {title, placeholder = "Add something here", disabled, loading, value = [], onChange} = props; | ||
|
||
const [entry, setEntry] = useState(""); | ||
const [entries, setEntries] = useState(value); | ||
|
||
function handleAddItem() { | ||
if (entry.trim()) { | ||
const updatedArray = [...entries, entry.trim()]; | ||
|
||
setEntries(updatedArray); | ||
onChange && onChange(updatedArray); | ||
setEntry(""); | ||
} | ||
} | ||
|
||
function handleRemoveItem(index: number) { | ||
const updatedArray = entries.filter((_, i) => i !== index); | ||
|
||
setEntries(updatedArray); | ||
onChange && onChange(updatedArray); | ||
} | ||
|
||
return ( | ||
<div className="relative w-full"> | ||
{title && <h3 className="text-lg font-semibold mb-2">{title}</h3>} | ||
|
||
<div className="flex gap-2 mb-4"> | ||
<Input | ||
key="multipleTextInput" | ||
type="text" | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
value={entry} | ||
onChange={(e) => setEntry(e.target.value)} | ||
/> | ||
|
||
<Button loading={loading} disabled={disabled} title="Add" onClick={handleAddItem} style="rounded" /> | ||
</div> | ||
|
||
<div className="relative w-full flex flex-wrap gap-2"> | ||
{entries.length > 0 && | ||
entries.map((value, index) => <Badge key={index} title={value} onRemove={() => handleRemoveItem(index)} />)} | ||
</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
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.