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

@acrool/react-picker

v0.1.2

Published

This is a react method to quickly combine buttons with Picker

Downloads

481

Readme

Acrool React Picker

NPM npm npm

npm downloads npm

Features

  • Quickly create various Pickers such as Datepicker, timepicker, Select dropdown, etc.
  • Plug and unplug using framer-motion
  • Simulate the browser's native drop-down menu behavior (click outside to close, lose focus to close, open the menu when the keyboard is pressed or blank)
  • The agent menu OnChange and value changes can be controlled freely and will be saved when the menu is closed.

Install

yarn add framer-motion @acrool/react-picker

in your packages. (Make the version of styled-component you use match the version of styled-component used in acrool-react-gird)

"resolutions": {
    "framer-motion": "^11.x"
}

Usage

add in your index.tsx

import "@acrool/react-picker/dist/index.css";

add in your App.tsx

import {isEmpty} from '@acrool/js-utils/equal';
import clsx from 'clsx';
import React, {ForwardedRef} from 'react';
import styled, {css} from 'styled-components';

import NumberKeyboard from './NumberKeyboard';
import {createPicker, usePicker} from '@acrool/react-picker';




interface IProps extends FCProps {
  value?: number
  options?: number[]
  onChange?: (value: number) => void
  placeholder?: string
}



/**
 * Select Number Keyboard
 */
const SelectNumberKeyboard = ({
    id,
    placeholder = '0',
}: IProps, ref?: ForwardedRef<HTMLButtonElement>) => {
  const Picker = usePicker();

  /**
   * Clean
   */
  const handleClear = (e: React.MouseEvent) => {
    e.stopPropagation();
    Picker.onChange(0);
  };

  const isPlaceholderValue = isEmpty(Picker.value);

  return <SelectNumberKeyboardRoot
          ref={ref}
          type="button"
          onMouseDown={Picker.toggle}
          isFocus={Picker.isInputFocus}
          onFocus={Picker.inputFocus}
    >
      <Text isPlaceholderValue={isPlaceholderValue}>
        {isPlaceholderValue ? placeholder: Picker.value}
      </Text>
  </SelectNumberKeyboardRoot>;
};


const Picker = (props: IProps) => {
  const Picker = usePicker();

  const handleClickPicker = (addNumber: number) => {
    let result = 0;
    const currValue = Picker.value ?? 0;
    if(addNumber >= 0){
      result = currValue + addNumber;
    }
    Picker.onChange(result);
  };

  return <NumberKeyboard
          data={props.options}
          onChange={handleClickPicker}
  />;
};

export default createPicker(
        SelectNumberKeyboard,
        Picker
);


const SelectNumberKeyboardRoot = styled.button<{
  isFocus?: boolean,
}>`
    transition: box-shadow .15s ease-in-out;

    ${props => props.isFocus && css`
        box-shadow: 0 0 0 0.2rem rgb(0 123 255 / 25%);
    `}

`;

If you need to automatically infer types


export default createPicker(
        SelectNumberKeyboard,
        Picker
) as <V extends any>(props: IProps<V>) => JSX.Element;

If you need to not hide trigger onChange


export default createPicker(
        SelectNumberKeyboard,
        Picker,
    {
        isEnableHideSave: false,
        isEnableClickOutSiteHidden: false
    }
) as <V extends any>(props: IProps<V>) => JSX.Element;

There is also a example that you can play with it:

Play react-editext-example

Precautions

  • The main control controls the opening and closing of the menu. You need to use onMousedown instead of onClick.
  • The main control needs to use button to have the Tab focus function, where react-hook-form is very useful
  • The main control needs to use button. If you want to add a clear button in the inner layer, remember that it cannot be button, because button > button is an html structure error, and you need to use onMousedown instead of onClick.

Ref warning

Warning: forwardRef render functions accept exactly two parameters: props and ref. Did you forget to use the ref parameter?

interface IProps {
  value: string, 
  onChange:(value: string) => void
}
const DateTimeField = (props: IProps) => {}

// fix to 
const DateTimeFieldAfter = (props: IProps, ref?: ForwardedRef<HTMLElement>) => {}

There is an onClick event in the outer layer, causing the picker to click and trigger

It should be set in the outer layer to prevent bubbling.

const handleOnClick = (e: React.MouseEvent) => {
    e.stopPropagation();
}

return <DropdownRoot onClick={handleOnClick}>
        <DropTitle>{i18n('page.workspaceTask.action.subTask', {def: 'SubTask'})}</DropTitle>
    </DropdownRoot>;

License

MIT © Acrool & Imagine