Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Frame Filtering UX #352

Merged
merged 11 commits into from
May 24, 2024
Next Next commit
Update filtering ux
- Allow users to select all checkboxes
- Change "Show all" prompt to "Clear filters" to emphasise the filtering pattern
  • Loading branch information
felixhabib committed May 16, 2024
commit 0c17eb931e639167516f2752857d7ba4d855895e
15 changes: 4 additions & 11 deletions src/Playroom/FramesPanel/FramesPanel.tsx
askoufis marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,20 @@ interface FrameHeadingProps {
const FrameHeading = ({ showReset, onReset, children }: FrameHeadingProps) => (
<div className={styles.title}>
<Heading level="3">{children}</Heading>
{showReset && <ResetButton onClick={onReset}>Show all</ResetButton>}
{showReset && <ResetButton onClick={onReset}>Clear filters</ResetButton>}
</div>
);

interface FrameOptionProps<Option> {
option: Option;
selected: boolean;
visible: Option[];
available: Option[];
onChange: (options?: Option[]) => void;
}
function FrameOption<Option>({
option,
selected,
visible,
available,
onChange,
}: FrameOptionProps<Option>) {
return (
Expand All @@ -71,13 +69,10 @@ function FrameOption<Option>({
type="checkbox"
checked={selected}
className={styles.checkbox}
onChange={(ev) => {
if (ev.target.checked) {
onChange={(event) => {
if (event.target.checked) {
const newVisiblePreference = [...visible, option];
const isOriginalList =
JSON.stringify(newVisiblePreference.sort()) ===
JSON.stringify([...available].sort());
onChange(isOriginalList ? undefined : newVisiblePreference);
onChange(newVisiblePreference);
} else {
onChange(visible.filter((p) => p !== option));
}
Expand Down Expand Up @@ -147,7 +142,6 @@ export default ({ availableWidths, availableThemes }: FramesPanelProps) => {
option={option}
selected={hasFilteredWidths && visibleWidths.includes(option)}
visible={visibleWidths}
available={availableWidths}
onChange={(newWidths) => {
if (newWidths) {
dispatch({
Expand Down Expand Up @@ -177,7 +171,6 @@ export default ({ availableWidths, availableThemes }: FramesPanelProps) => {
option={option}
selected={hasFilteredThemes && visibleThemes.includes(option)}
visible={visibleThemes}
available={availableThemes}
onChange={(newThemes) => {
if (newThemes) {
dispatch({
Expand Down