Skip to content

Commit

Permalink
Add filter in jsee and Accessibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xypnox committed Feb 14, 2024
1 parent c55ef43 commit fad4507
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 266 deletions.
46 changes: 44 additions & 2 deletions src/components/elements/atoms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export const Button = styled('button')`
color: ${theme.primary.color};
}
&&:focus-visible {
outline: 2px solid var(--primary-color);
}
&&:hover {
color: var(--primary-contrast);
background: var(--primary-color);
Expand Down Expand Up @@ -90,8 +95,13 @@ export const ButtonGroup = styled('div')`
border-radius: 0;
border: none;
flex: 1;
&:hover, &:focus, &:active {
box-shadow: none;
z-index: 3;
&:hover, &:active {
box-shadow: none;
}
&:focus-visible {
outline: none;
box-shadow: inset 0px 0px 0px 2px var(--primary-color);
}
&:first-child {
border-radius: ${theme.border.radius} 0 0 ${theme.border.radius};
Expand All @@ -112,3 +122,35 @@ export const GroupSeparator = styled('div')`
flex-shrink: 0;
background: ${theme.border.color};
`

export const IconInput = styled('div')`
${baseElementStyles}
padding: 0;
z-index: 2;
display: flex;
align-items: center;
border-radius: ${theme.border.radius};
border: 1px solid ${theme.border.color};
background: ${theme.surface};
transition: all 0.2s ease;
iconify-icon {
font-size: 1.25rem;
padding-left: 0.5rem;
}
&:has(input:focus-visible) {
outline: 2px solid var(--primary-color);
}
input {
flex: 1;
border: none;
background: transparent;
color: ${theme.text};
&:focus-visible {
outline: none;
}
}
`
137 changes: 137 additions & 0 deletions src/components/elements/dropselect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { For, createSignal, onMount, type JSX, Show } from "solid-js";
import { styled } from "solid-styled-components";
import { theme } from "../../theme";
import { Button, Input } from "./atoms";

interface DropSelectOption {
label: string;
value: string;
}

interface DropSelectProps {
label: string;
options: DropSelectOption[];
value: string;
onlyFromOptions?: boolean
onChange: (value: string) => void;
Footer?: () => JSX.Element;
}

const Label = styled('label')`
width: 100%;
display: flex;
flex-direction: column;
gap: 0.25rem;
`

const Dropdown = styled('div')`
position: relative;
display: flex;
flex-direction: column;
gap: 0.25rem;
`

const DropdownContent = styled('div')`
position: absolute;
top: calc(100% + 0.25rem);
left: 0;
right: 0;
background: ${theme.surface};
border: 1px solid ${theme.border.color};
border-radius: ${theme.border.radius};
z-index: 200;
padding: 0.5rem;
box-shadow: ${theme.cardShadow};
backdrop-filter: blur(10px);
display: flex;
align-items: stretch;
flex-direction: column;
gap: 0.25rem;
&.hidden {
display: none;
}
a {
width: max-content;
display: flex;
align-items: center;
gap: 0.25rem;
}
`

const SelectOptions = styled('div')`
display: flex;
flex-wrap: wrap;
align-items: stretch;
gap: 0.25rem;
`

export const DropSelect = (props: DropSelectProps) => {
const [focused, setFocused] = createSignal(false);
let dropdown: HTMLDivElement;

const onClickOutside = (e: MouseEvent) => {
if (dropdown && !dropdown.contains(e.target as Node)) {
setFocused(false)
}
}

const onFocusOutside = (e: FocusEvent) => {
if (dropdown && !dropdown.contains(e.target as Node)) {
setFocused(false)
}
}

onMount(() => {
document.addEventListener('click', onClickOutside)
document.addEventListener('focusin', onFocusOutside)
return () => {
document.removeEventListener('click', onClickOutside)
document.removeEventListener('focusin', onFocusOutside)
}
})

const onChange = (value: string) => {
if (props.onlyFromOptions) {
const option = props.options.find((o) => o.value == value)
if (option) props.onChange(option.value)
} else props.onChange(value)
}

return (
<Dropdown
ref={dropdown!}
>
<Label>{props.label}</Label>
<Input
type="text"
value={props.value}
onFocus={() => setFocused(true)}
onInput={(e) => onChange(e.currentTarget.value)}
/>
<DropdownContent classList={{ hidden: !focused() }}>
<SelectOptions>
<For each={props.options}>
{option => (
<Button
class="small"
classList={{ selected: option.value === props.value }}
onClick={() => {
setFocused(false)
props.onChange(option.value)
}}
>{option.label}</Button>
)}
</For>
</SelectOptions>
<Show when={props.Footer}>
{props.Footer!()}
</Show>
</DropdownContent>
</Dropdown>
)
}


2 changes: 2 additions & 0 deletions src/components/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const icons = {
"done": "ph:check-circle",

"error": "ph:warning-duotone",

"search": "ph:magnifying-glass-duotone",
}

const CustomizeIcon = `<path d="M4 10h8v1.47c0 .3-.24.53-.53.53H4.53a.53.53 0 0 1-.53-.53V10Z" fill="currentColor"/><rect opacity=".5" x="7" y="10" width="2" height="4" rx=".53" fill="currentColor"/><path opacity=".75" d="M4 6.53c0-.3.24-.53.53-.53H6v2.47c0 .3-.24.53-.53.53h-.94A.53.53 0 0 1 4 8.47V6.53Z" fill="currentColor"/><path opacity=".5" d="M4 2.53c0-.3.24-.53.53-.53h.94c.3 0 .53.24.53.53V5H4.53A.53.53 0 0 1 4 4.47V2.53Z" fill="currentColor"/><path opacity=".75" d="M7 2.53c0-.3.24-.53.53-.53h.94c.3 0 .53.24.53.53V6H7V2.53Z" fill="currentColor"/><path d="M7 7h2v1.47c0 .3-.24.53-.53.53h-.94A.53.53 0 0 1 7 8.47V7Z" fill="currentColor"/><path opacity=".75" d="M10 6h1.47c.3 0 .53.24.53.53v1.94c0 .3-.24.53-.53.53h-.94a.53.53 0 0 1-.53-.53V6Z" fill="currentColor"/><path opacity=".5" d="M10 2.53c0-.3.24-.53.53-.53h.94c.3 0 .53.24.53.53v1.94c0 .3-.24.53-.53.53H10V2.53Z" fill="currentColor"/>`
Expand Down
Loading

0 comments on commit fad4507

Please sign in to comment.