Skip to content

Commit

Permalink
feat(devtools): highlight color selector
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Oct 10, 2024
1 parent 1c36410 commit eacdb02
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
5 changes: 2 additions & 3 deletions packages/devtools/src/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const Graph = ({ clientCtx, getColor, width, height }: Props) => {
let display = 'list-item'
let background = 'none'

for (const { search, type } of ctx.spy(filters.list.array)) {
for (const { search, type, color } of ctx.spy(filters.list.array)) {
const _type = ctx.spy(type)

if (_type === 'off') continue
Expand All @@ -94,8 +94,7 @@ export const Graph = ({ clientCtx, getColor, width, height }: Props) => {
}

if (_type === 'highlight' && result) {
background = 'rgb(255 255 255 / 50%)'
}
background = `${ctx.spy(color)}a0` }
} catch {}
}

Expand Down
56 changes: 34 additions & 22 deletions packages/devtools/src/Graph/reatomFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,50 @@ const Filters = z.object({
name: z.string().readonly(),
search: z.string(),
type: z.enum(['match', 'mismatch', 'exclude', 'highlight', 'off']),
color: z.string(),
readonly: z.boolean().readonly(),
}),
),
})
type Filters = z.infer<typeof Filters>

const DEFAULT_COLOR = 'rgba(255 255 255 / 50%)'

const initState: Filters = {
hoverPreview: true,
inlinePreview: false,
timestamps: true,
valuesSearch: '',
list: [{ name: 'private', search: `(^_)|(\._)`, type: 'mismatch', readonly: true }],
list: [{ name: 'private', search: `(^_)|(\._)`, type: 'mismatch', color: DEFAULT_COLOR, readonly: true }],
}
const initSnapshot = JSON.stringify(initState)
const version = 'v14'
const version = 'v15'

const FilterButton = (props: JSX.IntrinsicElements['button']) => (
<button
css={`
width: 25px;
height: 20px;
padding: 0;
margin-right: 5px;
border: 2px solid transparent;
border-radius: 2px;
font-size: 14px;
filter: grayscale(1);
&[disabled] {
border: 2px solid rgb(21 19 50 / 20%);
}
`}
{...props}
/>
)
const FilterButton = ({
isInput,
...props
}: (JSX.IntrinsicElements['button'] & { isInput?: false }) | (JSX.IntrinsicElements['input'] & { isInput: true })) => {
const Component = isInput ? 'input' : 'button'
return (
// @ts-expect-error
<Component
css={`
width: 25px;
height: 20px;
padding: 0;
margin-right: 5px;
border: 2px solid transparent;
border-radius: 2px;
font-size: 14px;
filter: grayscale(1);
&[disabled] {
border: 2px solid rgb(21 19 50 / 20%);
}
`}
{...props}
/>
)
}

export const reatomFilters = (
{
Expand Down Expand Up @@ -157,11 +167,13 @@ export const reatomFilters = (
</FilterButton>
<FilterButton
isInput
title="highlight"
aria-label="highlight"
disabled={atom((ctx) => ctx.spy(filter.type) === 'highlight')}
style={{ 'font-size': '10px' }}
type="color"
style={{ 'font-size': '10px', filter: 'unset' }}
on:click={filter.type.setHighlight}
model:value={filter.color}
>
💡
</FilterButton>
Expand Down

0 comments on commit eacdb02

Please sign in to comment.