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

office-ui-redux-form-renderers

v1.1.5

Published

Wrapper components for office ui components to use in redux form fields.

Downloads

15

Readme

office-ui-redux-form-renderers

office-ui-redux-form-renderers is a collection of functions to pass into the the component prop of a Redux Form Field component. The functions take in the props passed into the Field Component as well as the Field's WrappedFieldProps and returns the Fabric UI component. There is also a validators file that contains a collection of functions that are passed into the validate props of the Redux Form Field component for validation.

Current components

  • TextField
  • Dropdown(with available multiSelect option)
  • Checkbox

Example Renderer

import {TextField, ITextFieldProps} from 'office-ui-fabric-react';
import React from 'react';
import {WrappedFieldProps} from 'redux-form';

type ReduxTextFieldProps = ITextFieldProps & WrappedFieldProps;

export default function ReduxTextField (props: ReduxTextFieldProps): JSX.Element {
  const {input, meta, ...other} = props;
  return (
    <TextField
      key={input.name}
      onChange={input.onChange}
      value={input.value}
      errorMessage={meta.error}
      {...other}
    />
  );
}

Our renderer function will recieve props from the Field component. The props provided by redux-form are divided into input and meta objects. The props under the input key are what connects your input component to Redux and are meant to be destructured into your component. The props under the meta key are metadata about the state of this field that redux-form is tracking for you.

Any custom props passed to Field will be merged into the props object on the same level as the input and meta objects. These are the props that Fabric UI expects, eg, ITextFieldProps.

Creating a Field and using a Renderer

Example of creating a form Field in your UI code.

import {Field} from 'redux-form/immutable';
import {numberValidator, TextField} from 'office-ui-redux-form-renderers';

...

<Field
  name='year'
  ariaLabel='year'
  label='Year'
  required
  validate={[numberValidator]}
  component={TextField}
/>

Notice that we are importing Field from 'redux-form/immutable' and not 'redux-form'. The validate prop is an array of fuctions that validate your field at field level. The component prop is the renderer that we created. Any props that you want to use for Fabric can be added as a prop here and will be passed down to our wrapped component.

Creating a New Renderer

To create a new renderer for another Fabric UI component, add a new tsx file in this directory and follow the same pattern as the current renderers. Then import and export the renderer in index.ts.

Using and Creating Validators.

Validators are functions that return an error message in the meta prop. Passing in an array of these functions will validate the component at the field level. It is also possible to do async blur and change validation. Examples of validators:

export const numberValidator = (value: string): string | undefined =>
  value && isNaN(Number(value))
    ? 'Must be a number'
    : undefined;

export const emailValidator = (value: string): string | undefined =>
  value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)
    ? 'Invalid email address'
    : undefined;