Code Monkey home page Code Monkey logo

practical-react-components's Introduction

Practical react components

A catalogue of React components, focused on ease-of-use.

To install the core package, run:

yarn add practical-react-components-core

This contains all the core components. All the icons are located in a separate practical-react-components-icons package.

Dependencies

Practical react components is dependent on some packages, in addition to react and react-dom, that need to be installed for it to work. Make sure the following packages are installed:

yarn add styled-components
yarn add react-transition-group
yarn add pepjs

If you are using practical-react-components-formik you also need to make sure the following packages are installed:

yarn add formik

Typescript

Install additional typings:

yarn add @types/styled-components

If you use Typescript and want to use styled-components, you need to add a file to your source directory, e.g.:

styled-components.d.ts

with the following contents:

import 'styled-components'
import { Theme } from './theme'

declare module 'styled-components' {
  export interface DefaultTheme extends Theme {}
}

in which case you should get proper typings for the theme prop in your own styled components.

Make sure this file is included in your tsconfig.json files, e.g. "include": ["src/styled-components.d.ts", "./src/index.ts"].

Electron

If you are using Practical react components with an Electron app you might have to add the following lines in the root of you package.json file.

"electronWebpack": {
  "whiteListedModules": [
    "practical-react-components-core",
    "styled-components"
  ]
}

Usage

Practical react components makes use of contexts to provide theme and toast creators. To make it possible to use the components, you need to wrap your app in a PracticalProvider.

On the provider you can optionally specify a theme and behaviors for toasts.

export const Entry: React.FC = () => {
  return (
    <PracticalProvider>
      <App />
    </PracticalProvider>
  )
}

In your app, you can then start using Practical react components:

export const App: React.FC = () => {
  const [text, setText] = useState()
  const { showSuccessToast } = useToasts()

  return (
    <AppContainer>
      <TextInput onValueChange={setText} />
      <SpaceBlock variant={16} />
      <Button
        label="Yay"
        onClick={() => showSuccessToast({ label: `You wrote: ${text}` })}
      />
    </AppContainer>
  )
}

For more information on what components are available and how to use them please visit the documentation.

License

Code and icons in these packages are licensed under the MIT license, except for icons in practical-react-components-icons from, or icons based on, Material Design icons by Google (licensed under the Apache License 2.0).

practical-react-components's People

Contributors

aantonsb avatar andsero avatar barnomasoz avatar boilund avatar brian-chano avatar danielkaxis avatar danlundgren1 avatar dotmaro avatar hitomiwin avatar lekoaf avatar mattias-kindborg-at-work avatar mattiasberlin avatar oggez avatar rikteg avatar sana-shana avatar scharinger avatar steabert avatar tigge avatar tobiaslilja2 avatar triplewdotcom avatar victoringvarsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

practical-react-components's Issues

Question: why dependencies and not peerDependencies

Why you use dependencies and not peerDependencies in the non-private packages in this repository, for example https://github.com/AxisCommunications/practical-react-components/blob/main/packages/core/package.json#L11?

Currently this repo forces exact dependencies when using its packages, wouldn't it be easier for the users if these dependencies were changed to peerDependencies with the required working range so the users can update the dependencies without a need for the repository to update them, for example when a bug is fixed in one of them?

Input: No longer possible to write correct values if step is defined

Describe the bug

In this issue #237 it was implemented to show integer values with decimal for number input. This implementation created issues and it might be a good idea to revert the change.

To reproduce

Specify for example step="0.1" for a NumberInput component and try to use backspace or changing the value.

Steps to reproduce the behavior:

  1. Go to packages/docs/src/mdx/coreComponents/Input.mdx
  2. Add "step={0.1}" to NumberInput
  3. Run yarn dev and open the browser
  4. Go to Components -> Input
  5. Enter a value, for example 1
  6. It displays 1.0
  7. Use backspace
  8. Change value
  9. See error

React DnD for the DraggableList

Would you consider allowing React DnD for the DraggableList to get smoother and with cross-browser support drag and drop in the component library via a peerDependency?

Consider releasing v1.0 for easier peerDependencies handling

I'm using this package in some of my internal packages which has it as peerDependencies but as the version is 0, e.g., 0.56.0 I'm not able to handle this in a nice way and have this packages as ^0.x in peerDependencies as per documentation but if some version has breaking changes than I'm in trouble.

As per link above:

  • ^1.2.3 := >=1.2.3 <2.0.0-0
  • ^0.2.3 := >=0.2.3 <0.3.0-0
  • ^0.0.3 := >=0.0.3 <0.0.4-0
  • ^1.x := >=1.0.0 <2.0.0-0
  • ^0.x := >=0.0.0 <1.0.0-0

using v1.0 will make easier handling of this package in peerDependencies

Improve Tab example

Tab example is a bit hard to understand and with weird text and icon combinations.

Improve it by making the example a bit more "real world".

Slider: ghost knob

When continuously saving to an api while dragging the slider, some requests can take a while before seeing visible changes. I wonder if we can implement a ghost knob or something similiar that is displaying the actual value/position.

Workflow could be something like
-> Save value
-> Get data from a subscription
-> The standard knob is displaying the value we saved
-> The ghost knob is displaying the subscription data
-> The ghost knob disappears when reaching the standard knob position

FormikRadioButtonGroup does not get an error state automatically

Describe the bug

When using FormikRadioButtonGroup together with Formik (obviously), the component doesn't automatically get an error state even if validation fails. You have to manually add it.

<FormikRadioButtonGroupField
  name="myFormField"
  options={[
    { label: 'Label1', value: '1'},
    { label: 'Label2', value: '2'},
  ]}
  error={formik.errors.myFormField}
/>

Toggle Button Group component does not have the correct CSS behavior

When using the example code(taken from documentation) in a independent project, Buttons do not show left-right border and color overflows when on focus/selected.

Code used :

import "./App.css";
import { Icon, ToggleButtonGroup, Typography } from "practical-react-components-core";
import { CalendarIcon, LocationIcon } from "practical-react-components-icons";

function App() {
  return (
    <div style={{ width: "500px" }} className="App">
       //Example code starts
        <ToggleButtonGroup
          onChange={(id) => console.log(id)}
          options={[
            {
              id: "24",
              content: <Typography>24</Typography>,
            },
            { id: "location", content: <Icon icon={LocationIcon} /> },
            {
              id: "disabled",
              content: <Typography>Disabled</Typography>,
              disabled: true,
            },
            {
              id: "btn",
              content: <Typography>click me</Typography>,
            },
            {
              id: "calendar",
              content: <Icon icon={CalendarIcon} />,
            },
          ]}
          values={["24"]}
        />
      //Example code ends
    </div>
  );
}
export default App;

Output:

ToggleButtonGroup_wrong.mp4

This issue is not visible in the documentation:

ToggleButtonGroup_correct.mp4

MultiSelect hover and selected looks the same but behaves differently

There's a small confusing detail that feels like an issue to me.

If one opens the drop down with the enter key and has the mouse over an option and presses enter one would think the grey option that the mouse is pointing on will be added to the list of selected options, but not, as the hover is not equal to the selection. I suggest we change the selected (focus) option to the one which the mouse points on or change the styling. Maybe a discussion we could take with a UX or QA person.

A help icon button in the header with some weird content

A new question mark icon appeared in the header which is probably supposed to show some help dialog but currently a dialog with some weird content is show:

Screenshot 2021-02-16 at 10 33 45

Screenshot 2021-02-16 at 10 33 52

Expected behaviour:

  • Help dialog with some help texts when clicking on the help icon in the header

Current behaviour:

  • A dialog with some weird content when clicking on the help icon in the header

Add a purpose to practical-react-components

Improve documentation by adding a purpose for this component library.

  • Why should anyone choose practical-react-components?
  • What do we do better than anyone else?
  • Where do we shine?
  • Why did we choose to develop this library?

Update snapshots

Please do not disclose security vulnerabilities as issues. See our security policy for responsible disclosures.

Describe the bug

When running yarn test -u on main branch, a few snapshots are updated.

To reproduce

Switch to main branch. Run yarn test -u

SearchSelect has small error in the documentation

In the file SearchSelect.mdx line:98 the code example says:

const [selected, setSelected] = useState([])

instead of:

const [selected, setSelected] = useState("")

The initial state should be an empty string to avoid this error:
image

Tooltip doesn't disappear

Please do not disclose security vulnerabilities as issues. See our security policy for responsible disclosures.

Describe the bug

Tooltips remain open when the tooltip is on the button and when it performs an action, like opening a dialog box.

To reproduce

Steps to reproduce the behavior:

  1. Upgrade practical-react-components to v1.3.0.
  2. Create a test component of IconButton with Tooltip that opens a dialog in docs page.
  3. See the error by opening the dialog.

Screenshots

tooltip
(Three tooltips get stuck in the screenshot)

Environment

  • practical-react-components version: v1.3.0

Additional context

It doesn't happen with v1.2.0

Wide Labels in Slider overlapping each other

Please do not disclose security vulnerabilities as issues. See our security policy for responsible disclosures.

Describe the bug

When a Label component has overflowing text, it should be cut off and be trailing with a '...',
for Slider, this is not the case.

If a text is too long in a Slider/Label component, it'll overlap and prevent functionality such as
clicking or interacting.

To reproduce

Please provide as much context as possible and describe the reproduction steps that someone else can follow to recreate the issue on their own.

A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps. Bugs without steps will not be addressed until they can be reproduced.

Steps to reproduce the behavior:

  1. Create two Label components that are shared within a Sliders Component context
  2. Have very long values on both labels/Tick configurations
  3. Text should now cause overlap that disrupts functionality of clicking

or

  1. Start up any version of a Camera that supports image settings in ADA
  2. Navigate to Image tab
  3. Switch language to Russian
  4. The tick configuration slider that is "Low noise" and "Low blur" should overlap

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • Axis device model: AXIS P3717-PLE Network Camera
  • Axis device firmware version: 11.0.66
  • Stack trace or logs: N/A
  • OS and version: N/A
  • Version: N/A

Additional context

There is a mixed behavior of how this is handled - in some places, when a overflowed text is
hovered - a full version of the string is represented - in other places, this is not the case.

Toast: Show toast in fullscreen

Describe the feature

Currently the ToastAnchor is in a fixed position at the root. This will not work when going into fullscreen on an element. For this to work the ToastAnchor must be placed inside the element that is in fullscreen. By exposing the ToastAnchor it would be possible to place the ToastAnchor where it's needed.

Added value

Show toasts for elements that are in fullscreen.

Popover: Fullscreen support

Describe the feature

Popover is by default rendered in the root layer, which it should. However, when using fullscreen on an element the popover is not shown since it's not a child to the fullscreen element. A nice addition would in that case be to tell the popover to append to the anchor element and not the root layer. The "issue" that I want to solve is having a select component working in fullscreen.

I have elaborated with z-index as well, but that seems like a no-go zone as far as I can tell. It doesn't seem possible to change the z-index on the fullscreen element and I fear it would lead to trouble if we would get it to work.

Added value

Consider a video in fullscreen. By adding this feature to the popover it would be possible to have selects, tooltips or any popover in fullscreen mode.

Slider: tick size and color

I wonder if it would be nice to increase the size of the tick label circles and the ability to override the color. I was then thinking that we should have default values but the ability to configurate them through tickConfig prop.

Because right now it doesn't really fit well in my opinion. It's not even noticeable that they are circles

MultiSelect missing overflow hidden

Multi select missing overflow: hidden for the chips used inside which results in chips with long labels moving the components inside (x and arrow) outside the component:

Screenshot 2022-02-21 at 12 14 14

By applying the code below fixes the issue:

  div[class^='MultiSelect__SelectInsideContainer'] {
    overflow: hidden;
  }

  div[class^='MultiSelect__ChipContainer'] {
    overflow: hidden;
  }

Table does not adapt to change in initialWidths

When initialWidths prop changes, the table does not adapt to this change (e.g. number of columns). This can happen when the number of columns isn't known when rendering the table, and the rendering is not delayed in order to show something during a loading phase.

Timepicker: Displaying 24.XX instead of 00.XX on some locales

Describe the bug

When selecting 0 in the timepicker. The time displays as 24.XX. Expected behaviour is 00.XX
The issue exists on chrome-based browser and is caused by default hourCycle attribute being set to 'h24' if hour12 is specified. It should be 'h23'.

More information regarding the issue can be found here:
tc39/ecma402#436

Information regarding hourCycle can be found here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle

To reproduce

  1. Change hour12 to false in packages/docs/src/mdx/coreComponents/DateTimePicker.mdx
  2. Select Components -> DateTimePicker
  3. Click button Change date and time
  4. Select 0 as hour
  5. See error

Screenshots

image-2022-02-24-11-31-10-869

Environment

  • Chrome based browser

Unnecessary npm publish of unchanged packages

Currently this repository publishes all the packages at once even if most of them contain no changes. For example, see v0.26.0...v0.27.0 where an icon was added but core and formik packages where publish with no changes in them at all. IMO this creates a confusion, for example, when you do not use an icons package in some project and see the new versions of the packages with no changes at them.

Tooltip unusable using touch

Please do not disclose security vulnerabilities as issues. See our security policy for responsible disclosures.

Describe the bug

When using a device which supports touch, it is not possible to see tooltips.

To reproduce

Try to see a tooltip on a mobile device (or by faking it using dectools in the browser)

Screenshots

N/A

Environment

  • Axis device model: Any
  • Axis device firmware version: Any
  • Stack trace or logs: N/A
  • OS and version: Windows 11, Debian 10
  • Version: [email protected]

Additional context

N/A

Searchable FormikMultiSelectField

For a project I'm working on, it would be beneficial if there could be a component that is a combination of a SearchSelect and a MultiSelect.

Would this be difficult to add?

Missing license for packages published to npm

Missing license for packages published to npm. When using license-webpack-plugin getting errors:

license-webpack-plugin: could not find any license type for practical-react-components-core in its package.json
license-webpack-plugin: could not find any license type for practical-react-components-formik in its package.json
license-webpack-plugin: could not find any license type for practical-react-components-icons in its package.json

so either license file should be copied to each package that is published to npm or main license file is included when publishing packages to npm.

MultiSelect component does not compile

There is an issue with props options in MultiSelect component when used in a separate react+typescript project.

Code used:

import "./App.css";
import { MultiSelect } from "practical-react-components-core";
import { useState } from "react";  
function App() {
  const tzOptions = [
    { value: "Africa/Abidjan", label: "Africa + Abidjan" },
    { value: "Africa/Accra", label: "Africa + Accra" }, 
  ];
  const [selected, setSelected] = useState([]);
  return (
    <MultiSelect
      options={tzOptions} //error here
      placeholder="Select..."
      width="full"
      value={selected}
      onChange={setSelected}
      noOptionsLabel="No options"
    />
  );
}
export default App;

Compilation error:

image

Menu should close when clicking on the icon when it's expanded

Currently menu does not close when you click on the icon when it's expanded, you need to click somewhere else outside the menu to close it:

menu

Current behaviour:
Clicking on menu's icon when it is expanded does not close the menu.

Expected behaviour:
Clicking on menu's icon when it is expanded closes the menu.

Slider: value > max, value < min breaks the component

A developer can specify minimum and maximum values and they often come from api's. This also applies for the value. Sometimes there can be bad data resulting in a value being larger than max and vice versa. This will break the component and we should at lease limit the position of the knob to the min and max positions to not break the gui.
slider_max
slider_min

Chip with icon still clickable when disabled

The icon of the element chip can still be 'clicked' when chip is set as disabled

Code used:

import "./App.css";
import { Chip } from "practical-react-components-core";
function App() {
  return <Chip text="chip is disabled" disabled onRemove={() => {}} />;
}
export default App;

Output:

chip_disabled_icon_clickable.mp4

*Field component's label does not consider disabled

When a disabled property is set to true for the *Field component the label is still shown as non-disabled.

E.g.,

<FormikSelectField
  name="name"
  options={[]}
  label="label"
  variant="framed"
  width="small"
  disabled={true}
/>

Compare how the label for the disabled switch looks:
Screenshot 2022-02-10 at 10 25 14

compared to the, for example, SelectField's label:
Screenshot 2022-02-10 at 10 25 56

Card has a small error in the documentation

The code example in Card documentation has the components Switch and RadioButtonGroup with props value and label respectively.
image
image

All value props should be changed to checked instead and label removed, since it doesn't exist in RadioButtonGroup component.

NumberInput: Show integer values with decimals

Describe the feature

By default an input element is showing integer values without decimals even when step is specified. It would be a nice feature to show integers together with decimals.

Current:
0.8
0.9
1
1.1
1.2

Improvement
0.8
0.9
1.0
1.1
1.2

Added value

Clarity

Additional context

For a better user experience it would make it more clear to display integer values with decimals when all of the other numbers are.

Stepper: component as a stepper label

Describe the feature

Use case: add info icon to a stepper label.
You can add string or React-node to the label.

Added value

More flexibility.

Additional context

certificate-filename

SelectList has a small error in the documentation

In the file SelectList.mdx line:46 the code example says:
value={() => {}}

Which gives this error:
image

value should have an empty string or a value already included in options to have a similar look as shown in the Demo

Example:

image

Expandable example preview is not shown

In Expandable.mdx the example code is missing type=live in order to have a preview of the example in the documentation.

Current view

image

Expected view

image

Also, disabled should be added to Arrow component in the example code in order to avoid this error:

image

Link

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.