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

feat: make filter options collapsible #815

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/components/OptionsForm.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,16 @@
height: 2rem;
padding: 0.5rem;
}

.toggleButton {
display: flex;
justify-content: center;
align-items: center;
background: none;
border: none;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
cursor: pointer;
maggienegm marked this conversation as resolved.
Show resolved Hide resolved
}
110 changes: 74 additions & 36 deletions src/components/OptionsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"use client";

import { useState } from "react";
import { PackageOwnership } from "tidelift-me-up";

import { CallToAction } from "./CallToAction";
Expand All @@ -16,6 +19,14 @@ export interface OptionsFormProps {
export function OptionsForm({ options }: OptionsFormProps) {
const ownerships = new Set(options.ownership);

const [isSecondaryOptionsVisible, setIsSecondaryOptionsVisible] = useState(
!options.username,
);
maggienegm marked this conversation as resolved.
Show resolved Hide resolved

const toggleSecondaryOptions = () => {
setIsSecondaryOptionsVisible(!isSecondaryOptionsVisible);
};

return (
<form className={styles.optionsForm}>
<div className={styles.primaryOptions}>
Expand All @@ -39,44 +50,71 @@ export function OptionsForm({ options }: OptionsFormProps) {
</div>

<div className={styles.secondaryOptionsArea}>
<h2 className={styles.h2}>optionally, filter by:</h2>
<div className={styles.secondaryOptions}>
<div className={styles.secondaryOptionArea}>
<label className={styles.labelSecondary} htmlFor="since">
Updated Since
</label>
<input
className={styles.inputSecondary}
defaultValue={options.since && options.since.toString()}
id="since"
name="since"
type="date"
></input>
</div>
<button
maggienegm marked this conversation as resolved.
Show resolved Hide resolved
className={styles.toggleButton}
onClick={toggleSecondaryOptions}
type="button"
>
optionally, filter by
<svg
fill="none"
height="24"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
style={{
transform: isSecondaryOptionsVisible
? "rotate(180deg)"
: "rotate(0deg)",
}}
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M6 9l6 6 6-6" />
</svg>
</button>

<fieldset className={styles.secondaryOptionArea} name="ownership">
<legend className={styles.legendSecondary}>
Relationship to Project
</legend>
<div className={styles.fieldsetOptions}>
{(["author", "maintainer", "publisher"] as const).map(
(ownershipForm) => (
<div className={styles.secondaryOption} key={ownershipForm}>
<input
defaultChecked={ownerships.has(ownershipForm)}
id={ownershipForm}
name={ownershipForm}
type="checkbox"
/>
<label htmlFor={ownershipForm}>
{upperFirst(ownershipForm)}
</label>
</div>
),
)}
{isSecondaryOptionsVisible && (
<div className={styles.secondaryOptions}>
<div className={styles.secondaryOptionArea}>
<label className={styles.labelSecondary} htmlFor="since">
Updated Since
</label>
<input
className={styles.inputSecondary}
defaultValue={options.since && options.since.toString()}
id="since"
name="since"
type="date"
></input>
</div>
</fieldset>
</div>

<fieldset className={styles.secondaryOptionArea} name="ownership">
<legend className={styles.legendSecondary}>
Relationship to Project
</legend>
<div className={styles.fieldsetOptions}>
{(["author", "maintainer", "publisher"] as const).map(
(ownershipForm) => (
<div className={styles.secondaryOption} key={ownershipForm}>
<input
defaultChecked={ownerships.has(ownershipForm)}
id={ownershipForm}
name={ownershipForm}
type="checkbox"
/>
<label htmlFor={ownershipForm}>
{upperFirst(ownershipForm)}
</label>
</div>
),
)}
</div>
</fieldset>
</div>
)}
</div>
</form>
);
Expand Down
Loading