Skip to content

Commit

Permalink
v0.2.4-beta.4
Browse files Browse the repository at this point in the history
  • Loading branch information
CarcajadaArtificial committed Aug 10, 2023
1 parent b9af902 commit 945a749
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 35 deletions.
26 changes: 21 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# Changelog

## v0.2.4-beta.3
## v0.2.4-beta.4

### Added utility routes in `import_map.json`
- `/components/**/setup.ts`
- `/mod.ts`
- `/src/utils.ts`
### Added the Chiplist component
- `/components/Chiplist/index.tsx`
- `/components/Chiplist/setup.ts`
- `/mod`
- `/src/scss/components.scss`
- `/static/style.css`

### Added remove interaction to the chip component
- `/components/Chip/index.tsx`
- `/components/Chip/setup.ts`

### Added Island for testing
- `/islands/Island.tsx`
- `/fresh.gen.ts`
- `/routes/index.tsx`

### Minor updated
- `/components/Input/index.tsx`
- `/static/content.md`

## Changes so far

- Added the `<Chip/>` component.
- Added the `<Chiplist/>` component.
- Fixed components' use of `nostyle` and `nostyleAll`.

## Roadmap
Expand Down
19 changes: 16 additions & 3 deletions components/Chip/index.tsx
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>
);
}
9 changes: 8 additions & 1 deletion components/Chip/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { applyDefaults, cn, opt, partializeClasses } from 'utils';
import { iComponent, iFwd } from 'types';

export type iChip = iComponent<HTMLLIElement> & {
onRemove?: (ev: Event) => void;
fwd: Partial<{
content: iFwd<HTMLSpanElement>;
remove_button: iFwd<HTMLButtonElement>;
}>;
};
Expand All @@ -14,7 +16,7 @@ const defaults: iChip = {
export default (props: Partial<iChip>) => {
const p = applyDefaults<iChip>(defaults, props);

const { remove_button } = p.fwd;
const { remove_button, content } = p.fwd;

const classes = partializeClasses({
chip: opt(
Expand All @@ -27,6 +29,11 @@ export default (props: Partial<iChip>) => {
remove_button?.class,
remove_button?.nostyle || p.nostyleAll,
),
content: opt(
cn('comp-chip_content'),
content?.class,
content?.nostyle || p.nostyleAll,
),
});

delete p.class;
Expand Down
26 changes: 26 additions & 0 deletions components/Chiplist/index.tsx
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>
);
}
31 changes: 31 additions & 0 deletions components/Chiplist/setup.ts
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 };
};
44 changes: 21 additions & 23 deletions components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@ export default function (props: Partial<iInput>) {
return (
<div ref={fwd.container?.ref} class={c.container}>
<label ref={fwd.label?.ref} class={c.label}>
{label === ''
? null
: (
<Text
nostyleAll={nostyleAll}
fref={fwd.text?.fref}
noMargins
class={c.text}
>
<>{label}</>
{p.required
? (
<sup
ref={fwd.required?.ref}
title='Required'
class={c.required}
>
*
</sup>
)
: null}
</Text>
)}
{label === '' ? null : (
<Text
nostyleAll={nostyleAll}
fref={fwd.text?.fref}
noMargins
class={c.text}
>
<>{label}</>
{p.required
? (
<sup
ref={fwd.required?.ref}
title='Required'
class={c.required}
>
*
</sup>
)
: null}
</Text>
)}
<input ref={fref} class={c.input} {...p} />
</label>
{error
Expand Down
5 changes: 4 additions & 1 deletion fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as $1 from './routes/index.tsx';
import * as $2 from './routes/md.tsx';
import * as $3 from './routes/test/gradient.tsx';
import * as $4 from './routes/test/input.tsx';
import * as $$0 from './islands/Island.tsx';

const manifest = {
routes: {
Expand All @@ -16,7 +17,9 @@ const manifest = {
'./routes/test/gradient.tsx': $3,
'./routes/test/input.tsx': $4,
},
islands: {},
islands: {
'./islands/Island.tsx': $$0,
},
baseUrl: import.meta.url,
};

Expand Down
29 changes: 29 additions & 0 deletions islands/Island.tsx
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>
);
}
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { default as Panel } from './components/Panel/index.tsx';
export { default as Markdown } from './components/Markdown/index.tsx';
export { default as Gradient } from './components/Gradient/index.tsx';
export { default as Chip } from './components/Chip/index.tsx';
export { default as Chiplist } from './components/Chiplist/index.tsx';
export * from 'enums';
export * from 'types';
export * from 'utils';
7 changes: 6 additions & 1 deletion routes/index.tsx
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>
);
}
14 changes: 14 additions & 0 deletions src/scss/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,18 @@
height: var(--s-one-and-half);
border-radius: var(--s-eighth);
}

&_content {
max-width: var(--s-fifteen);
overflow-x: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Chiplist
.comp-chiplist {
display: flex;
gap: var(--s-third);
}
1 change: 0 additions & 1 deletion static/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

> Blockquote Lorem ispum

- Buildscript

```ts
Expand Down
11 changes: 11 additions & 0 deletions static/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 945a749

Please sign in to comment.