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

new-flawless-ui

v1.1.2

Published

- [Conditional](#Conditional) - [Network](#Network)

Downloads

3

Readme

Features

Conditional

Group of components helping you in rendering components from lists or expressions.

Components

Show

Renders chilrend props if when prop is true

<Show when={expression}>
    {jsx}
</Show>

IfElse

If want to have a if-else statemnet you can wrap your <Show /> components with this. it will only render the first <Show /> component that has a true expression in its when prop

<IfElse>
    <Show when={expression}>
        {jsx}
    </Show>
    <Show when={expression}>
        {jsx}
    </Show>
    <Show when={expression}>
        {jsx}
    </Show>
</IfElse>

For

Has a variaty of ways to help you render an array with ease

<For list={array}>
    {item => (
        {jsx}
    )}
</For>

If you have small changes in your jsx depending on the index or it being the first or last item you can use it like this

<For list={array}>
    {(item, index, isFirst, isLast) => (
        {jsx}
    )}
</For>

If your jsx is completely for first or last item you can pass their function in the firstItem and lastItem. They will render in the correct place and it won't render again in the children function

<For 
    list={array}
    firstItem={item => ({jsx})}
    lastItem={item => ({jsx})}
>
    {item => (
        {jsx}
    )}
</For>

Switch

Works just like a normal switch case

<Switch expression={variable}>
    <Case value={value1} break>
        {jsx}
    </Case>
    <Case value={value2}>
        {jsx}
    </Case>
    <Case default>
        {jsx}
    </Case>
</Switch>

Network

It handles loading and feedback for HTTP requests.

Config

First you need to install axios

npm i axios

then you can create an axios instance and pass it to the config file and pass it to the FlawLessUI component

const instance = axios.create({
    baseURL: BASE_URL,
})

import { FlawLessUI, createConfig } from 'flawless-ui'

const config = createConfig({
    axiosInstance: instance,
})

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
)
root.render(
  <FlawLessUI config={config}>
    <App />
  </FlawLessUI>
)

Components

Hooks

Loading

It handles loading for the given url

useEffect(() => {
    getData()
}, [])

const getData = async () => {
  await api.get(URL)
}

return (
    <Loading url={URL}>
        {(loading: boolean) => (
            <>
              {loading ? 'loading' : 'done'}
            </>
         )}
     </Loading>
)

HttpFeedback

First you should create your Alert components and pass to the to the config file

Config

import { createConfig } from 'flawless-ui'

const config = createConfig({
    ...restOfConfig,
    components: {
        alerts: {
          success: (props: AlertI) => <div>S - {props.title} - {props.message}<button onClick={props.onClose}>close</button></div>,
          error: (props: AlertI) => <div>E - {props.title} - {props.message}<button onClick={props.onClose}>close</button></div>,
        },
    },
})

Http Methods

By default HttpFeedback handles error for all request but success for only post, put, patch and delete requests. You can change this how ever by passing an array of methods to the httpMethods of config

import { createConfig, HTTP_METHODS } from 'flawless-ui'

const config = createConfig({
  ...restOfConfig,
  httpMethods: [...HTTP_METHODS, 'get'],
})

Then you can use it like this

useEffect(() => {
    getData()
}, [])

const getData = async () => {
  await api.get('seed/picsum/200/300')
}

return (
    <HttpFeedback 
        url={URL}
    />
)

The message and title passed to the alert component come from 3 methods:

onError and onSuccess props

If these functions return an object with a message key value pair it will be passed to the alert component

<HttpFeedback 
    url={URL}
    onError={data => ({message: data.errorMessage, title: 'Error'})
/>

Status Code Messages

You can use the default STATUS_CODE_MESSAGES that are already in the config file or you change the messages to you liking

useLoading

If not given a url it will return true if any request is being made or if given a url only returns true for that url

const loading = useLoading()

return (
    <>
        {loading ? 'loading' : 'done'}
    </>
)