-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9af902
commit 945a749
Showing
13 changed files
with
188 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import Text from '../Text/index.tsx'; | ||
import setup, { iChip } from './setup.ts'; | ||
|
||
export default function (props: Partial<iChip>) { | ||
const { c, nostyle, nostyleAll, fref, children, ...p } = setup(props); | ||
const { c, nostyle, nostyleAll, fref, children, onRemove, ...p } = setup( | ||
props, | ||
); | ||
|
||
return ( | ||
<li ref={fref} class={c.chip} {...p}> | ||
<>{children}</> | ||
<button class={c.remove_button}>×</button> | ||
<Text class={c.content}>{children}</Text> | ||
<button | ||
onClick={onRemove} | ||
onKeyPress={(ev) => { | ||
if (onRemove && (ev.key === 'Enter' || ev.key === 'Space')) { | ||
onRemove!(ev); | ||
} | ||
}} | ||
class={c.remove_button} | ||
> | ||
× | ||
</button> | ||
</li> | ||
); | ||
} |
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,26 @@ | ||
import setup, { iChiplist } from './setup.ts'; | ||
import Chip from '../Chip/index.tsx'; | ||
|
||
export default function (props: Partial<iChiplist>) { | ||
const { c, nostyle, nostyleAll, fref, fwd, values, onRemove, ...p } = setup( | ||
props, | ||
); | ||
|
||
return ( | ||
<ul ref={fref} class={c.list} {...p}> | ||
{values.map((value) => ( | ||
<Chip | ||
class={c.chip} | ||
onRemove={onRemove} | ||
fwd={{ | ||
remove_button: { | ||
class: c.remove_button, | ||
}, | ||
}} | ||
> | ||
{value} | ||
</Chip> | ||
))} | ||
</ul> | ||
); | ||
} |
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 @@ | ||
import { applyDefaults, cn, opt, partializeClasses } from 'utils'; | ||
import { iComponent, iFwd } from 'types'; | ||
|
||
export type iChiplist = iComponent<HTMLUListElement> & { | ||
onRemove?: (ev: Event) => void; | ||
values: string[]; | ||
fwd: Partial<{ | ||
chip: iFwd<HTMLLIElement>; | ||
remove_button: iFwd<HTMLButtonElement>; | ||
}>; | ||
}; | ||
|
||
const defaults: iChiplist = { | ||
values: [], | ||
fwd: {}, | ||
}; | ||
|
||
export default (props: Partial<iChiplist>) => { | ||
const p = applyDefaults<iChiplist>(defaults, props); | ||
|
||
const { remove_button, chip } = p.fwd; | ||
|
||
const classes = partializeClasses({ | ||
list: opt(cn('comp-chiplist'), p.class, p.nostyle || p.nostyleAll), | ||
chip: cn(chip?.class), | ||
remove_button: cn(remove_button?.class), | ||
}); | ||
|
||
delete p.class; | ||
return { c: classes, ...p }; | ||
}; |
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,29 @@ | ||
import { useState } from 'preact/hooks'; | ||
import Chiplist from '../components/Chiplist/index.tsx'; | ||
import Input from '../components/Input/index.tsx'; | ||
|
||
export default function () { | ||
const [values, setValues] = useState<string[]>([]); | ||
|
||
return ( | ||
<div> | ||
<Input | ||
label='New tag' | ||
onkeyup={(ev) => { | ||
if (ev.key === 'Enter') { | ||
setValues([...values, (ev.target as HTMLInputElement).value]); | ||
(ev.target as HTMLInputElement).value = ''; | ||
} | ||
}} | ||
/> | ||
<Chiplist | ||
onRemove={(ev: Event) => { | ||
const target = ev.target as HTMLButtonElement; | ||
const chipValue = (target.previousSibling as HTMLElement).innerHTML; | ||
setValues(values.filter((value) => value !== chipValue)); | ||
}} | ||
values={values} | ||
/> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
// import { } from '../mod.ts'; | ||
import Island from '../islands/Island.tsx'; | ||
import { Header, Main } from '../mod.ts'; | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<Header></Header> | ||
<Main layout_type='center'> | ||
<Island /> | ||
</Main> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ | |
|
||
> Blockquote Lorem ispum | ||
|
||
- Buildscript | ||
|
||
```ts | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.