npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@washingtonpost/wpds-input-search

v1.24.0

Published

WPDS Input Search

Downloads

2,157

Readme

Search

import { InputSearch } from "@washingtonpost/wpds-ui-kit";

function Component() {
  return <InputSearch />;
}

Search component so far (files updated/created/changed):

Search.tsx

The main file. Everything is up to date. Could perhaps use some comments? But it's set up as the rest of our more complex components are. This is where you pass the openOnFocus prop. However, it only opens the Search.Popover when something has already been typed. If the input is completely empty, the popover won't be triggered. Hadn't yet started to even address this issue yet.

TODO: (goes with what's in SearchPopover.tsx and SearchInput.tsx comments) Popover needs to be triggered when the input is focused but nothing has been typed in yet.

SearchInput.tsx

This is where the input part of the component lives. I'm using/extending the WPDS input-text component with type=search. The current version of the search input covers up the search button with the clear button when something is typed in. This means that there's no way to click the search button and it relies solely on onEnter functionality. After a chat with design, we decided to update all search inputs to have both the clear 'X' button and the search button.

TODO: when you press the search button the search should be run TODO: when you focus on the input (before typing anything) the popover should open with some preloaded content TODO: when you press the clear button, it clear out the text but then when you focus back in it brings back the old content. I think the ref is not getting cleared out correctly.

InputText/InputText.tsx

This is the main input component. Trying to keep all other functionality the same, we now do several things for the search input alone. First, we now override/hide the default search clear button for both wekit and edge (will need to test on edge too).

SearchList.tsx

This is the component that holds the result contents. In this component I basically just remove the built-in paddings and margins from reach-ui, align, and set the overflowY.

TODO: haven't taken into account overflowX yet. Something to think about

SearchListItem.tsx

This is the component that holds each result. This component unsets the listItem styles inherited from default list itmes and sets the set height per item as specified by the specs. Also, it seems that the only way to style the parts of the results that match what's already been typed by the user is by targeting [data-user-value="true"]. It's the cleanest way I could find, but perhaps you can find another?

TODO: design doesn't take into account result items that are wider than the container. Should it wrap? Should it ellipse? Nobody knows.

SearchPopover.tsx

This component is the main container that holds all the things and that opens when we interact with the input. I am unsure how to get it to open on focus (with nothing typed). As of now, it opens on focus when you pass openOnFocus to the main Search component. However, you have to have typed something in already for this to work.

SearchEmptyState.tsx

Most everything else should be finished and look according to spec

SearchLoadingState.tsx

Most everything else should be finished and look according to spec

SearchOtherState.tsx

Since both the empty state and the loading state have the same formatting and the only things that differ are the specific icon used and the text that goes with it, I create this abstraction to try and remove some code duplication. The main thing left to do in this file is to remove the any types. You can also rename this file? I was trying to communicate that it's a wrapper for the different type of states the component can have outside of the main one...

README.md

Other than these notes, I haven't updated anything yet on this file.

TODO: update README with relevant information.

Other notes:

Have been using the code sandbox example/exploration I did for the spike as a reference for some things too

TODO: Design wants filtering within the actual popover TODO: onResultHover (mentioned in zeplin) TODO: Add docs + examples (code)