
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
react-customize-token-input
Advanced tools
A react token (tag) input component. Allow customize data structure and Look & Feel
Live Demo: https://seawind543.github.io/react-token-input/
React TokenInput (react-customize-token-input)
A react token (tag) controlled
input component, which support:
label
Demo, delete button
Demo, or even override the whole Token component
Demo.yarn add react react-customize-token-input
react-token-input
and its styles in your application by:import TokenInput from 'react-customize-token-input';
// Be sure to include styles at some point, probably during your bootstraping
import 'react-customize-token-input/dist/react-customize-token-input.css';
yarn install
to install required packages.yarn dev
to launch webpack-dev-server
.「wds」: Project is running at http://0.0.0.0:8000/
「wds」: webpack output is served from /
「wds」: Content not from webpack is served from ../docs
Note: To stop the program, just type
ctrl + c
in command console.
http://localhost:8000/
to see result.See Live Examples: https://seawind543.github.io/react-token-input/
Note: Sources code of Examples in the folder examples
// Assign style to the TokenInput
style: PropTypes.object,
// Assign className to the TokenInput
className: PropTypes.string,
// Specific TokenInput is `readOnly` or not
readOnly: PropTypes.bool,
// Specific TokenInput should be autoFocus or not
autoFocus: PropTypes.bool,
// Placeholder of TokenInput
placeholder: PropTypes.string,
// [Required] An array of tokenValue of TokenInput
tokenValues: PropTypes.array.isRequired,
/**
* A callback function invoked when tokenValues update
*
* onTokenValuesChange(modifiedTokenValues)
*
* @ modifiedTokenValues
* Type: An array of tokenValue of TokenInput
* Description: Updated tokenValues
*/
onTokenValuesChange: PropTypes.func,
/**
* An array of characters for split the user input string.
* For example,
* Split the user input string `abc;def` into `['abc', 'def']`
* by separators `[';']`
*
* Note:
* It take the `String.prototype.split()` and `RegExp` to split the user input string.
* Make sure your customized separators could be used with `RegExp`.
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
*/
separators: PropTypes.array,
/**
* A callback function for preprocessing the user input string
* (after it is split into `array of value`).
*
* Note: This function execute after `split` but before `onBuildTokenValue`
*
* [Use case 1]
* Make your normalize process in this function, such as `String.prototype.trim()`.
*
* [Use case 2]
* Sometimes, we will want to auto-fit user input, this function could help with it.
* For example, the user input string is `www.google.com`,
* and we want to auto-fit it into `http://www.google.com` and `https://www.google.com`.
*
*
* onPreprocess(inputStringValues)
*
* @ inputStringValues
* Type: An array of string values
* Description:
* The user input string values // (split from the user input string by the `separators`)
*
* @ return
* Type: An array of string values
* Description: The values after preprocess
*/
onPreprocess: PropTypes.func,
/**
* A callback function for building `user input string value` into
* the `tokenValue` (customize data structure).
*
* Note: You could make your normalize process in this function too.
*
* onBuildTokenValue(stringValue)
*
* @ stringValue
* Type: string
* Description: The user input value // (A value split by separators)
*
* @ return
* Type: any (string | number | object | customize data structure)
* Description: customize data structure
*/
onBuildTokenValue: PropTypes.func,
/**
* A callback function invoked when end-user typing but not become token yet
*
* onInputValueChange(newValue, previousValue)
*
* @ newValue
* Type: string
* Description: end-user input string
*
* @ previousValue
* Type: string
* Description: previous end-user input string
*/
onInputValueChange: PropTypes.func,
/**
* A callback function for validate tokenValue
*
* onTokenValueValidate(tokenValue, tokenIndex, tokenValues)
*
* @ tokenValue
* Type: any (string | number | object | customize data structure)
* Description: The tokenValue build by `onBuildTokenValue`
*
* @ tokenIndex
* Type: number
* Description: The array index for this tokenValue in tokenValues
*
* @ tokenValues
* Type: array
* Description: The array of tokenValue of TokenInput
*
* @ return
* Type: any (string | number | object | customize data structure)
* Description:
* The customize error.
* Specific the token's validate status or errorMessage.
* Could be an error message to display or error object
*
* Will be use by `onGetTokenErrorMessage`
*/
onTokenValueValidate: PropTypes.func,
/**
* A callback function for getting customizes `className` for a token
*
* onGetTokenClassName(tokenValue, tokenMeta)
*
* @ tokenValue
* Type: any (string | number | object | customize data structure)
* Description: The tokenValue build by `onBuildTokenValue`
*
* @ tokenMeta
* Description: token's meta data
* {
* // A private key for render
* key: string,
*
* // Specific the token is activated for `edit` or not
* activated: boolean,
*
* // Customize data structure built by `onTokenValue Validate`
* // Specific the token's validate status or errorMessage
* error: any,
* }
*
* @ return
* Type: string
* Description: The customizes className
*/
onGetTokenClassName: PropTypes.func,
/**
* A callback function for getting displayable `label` for a token
* Apply this to customize the token's content
* For example, render token with `icon` or `Additional text`
*
* onGetTokenDisplayLabel(tokenValue, tokenMeta)
*
* @ tokenValue
* Type: any (string | number | object | customize data structure)
* Description: The tokenValue build by `onBuildTokenValue`
*
* @ tokenMeta
* Description: token's meta data
* {
* // A private key for render
* key: string,
*
* // Specific the token is activated for `edit` or not
* activated: boolean,
*
* // Customize data structure built by `onTokenValue Validate`
* // Specific the token's validate status or errorMessage
* error: any,
* }
*
* @ return
* Type: string || react node
* Description: The token's content.
* By default, will apply `getDefaultTokenEditableValue`
*/
onGetTokenDisplayLabel: PropTypes.func,
/**
* A callback function for render content of the delete button for a token
* Apply this to customize the token's content of delete button
* For example, replace the build-in x by Google font material-icons
*
* onRenderTokenDeleteButtonContent()
*
* @ return
* Type: react node
* Description: The content of the delete button of the token.
* By default, TokenInput render a build-in x icon
*/
onRenderTokenDeleteButtonContent: PropTypes.func,
/**
* A callback function for getting `string input value`
* from `tokenValue` for the end-user to perform `edit`
*
* onGetTokenEditableValue(tokenValue)
*
* @ tokenValue
* Type: any (string | number | object | customize data structure)
* Description: The tokenValue build by `onBuildTokenValue`
*
* @ return
* Type: string
* Description: The value for end-user to `edit` in an input field
*/
onGetTokenEditableValue: PropTypes.func,
/**
* A callback function for getting the error message from the customize error
* The `customize error` is generate by `onTokenValueValidate`
*
* onGetTokenErrorMessage(tokenValue, tokenMeta)
*
* @ error
* Type: customize error
* Description: customize error
*
* @ return
* Type: string | any
* Description: The error message to describe an invalid token
*/
onGetTokenErrorMessage: PropTypes.func,
/**
* A customize react functional component for rendering a token
* Apply this to customize all token function.
*
* customizeTokenComponent={MyToken}
*/
customizeTokenComponent: PropTypes.func,
className: '',
readOnly: false,
autoFocus: false,
placeholder: '',
// TokenCreator
separators: [
',',
';',
'\n', // for copy and paste
'\r', // for copy and paste
'\r\n', // for copy and paste
];
onBuildTokenValue: buildDefaultTokenValue,
onInputValueChange: () => {}, // Dummy function
onTokenValueValidate: () => undefined,
// Token
onGetTokenClassName: () => '',
onGetTokenDisplayLabel: getDefaultTokenEditableValue,
onGetTokenEditableValue: getDefaultTokenEditableValue,
onGetTokenErrorMessage: getDefaultTokenErrorMessage,
Could also reference this Example Demo and its source code ExampleCustomizeToken
from the folder examples
.
// Same as props of TokenInput
readOnly: PropTypes.bool.isRequired,
// tokenValue of token
tokenValue: PropTypes.any.isRequired,
// tokenMeta of token
tokenMeta: PropTypes.object.isRequired,
// Same as props `onGetTokenClassName` of TokenInput
onGetClassName: PropTypes.func.isRequired,
// Same as props `onGetTokenDisplayLabel` of TokenInput
onGetDisplayLabel: PropTypes.func.isRequired,
// Same as props `onRenderTokenDeleteButtonContent` of TokenInput
onRenderDeleteButtonContent: PropTypes.func,
// Same as props `onGetTokenEditableValue` of TokenInput
onGetEditableValue: PropTypes.func.isRequired,
// Same as props `onGetTokenErrorMessage` of TokenInput
onGetErrorMessage: PropTypes.func.isRequired,
// Editing
// Same as props `onBuildTokenValue` of TokenInput
onBuildTokenValue: PropTypes.func.isRequired,
/**
* A callback function, which should be `invoked` when end-user `start editing`
*
* Note:
* Call this function to tell TokenInput it is start to editing the token.
* As result, TokenInput will set `tokenMeta.activate` to `true`
*
* onEditStart()
*
* @ return
* Type: void
*/
onEditStart: PropTypes.func.isRequired,
/**
* A callback function, which should be `invoked` when end-user `end editing`
*
* Note:
* Call this function to tell TokenInput it is finish editing the token.
* As result, TokenInput will set `tokenMeta.activate` to `false`
*
* onEditEnd(newTokenValue?)
*
* @ newTokenValue
* Type: undefined | any (string | number | object | customize data structure)
* Description:
* The new tokenValue build by `onBuildTokenValue.
* TokenInput will update it, and
* TokenInput will call `onTokenValuesChange`
*
* Note:
* When newTokenValue is `undefined`,
* TokenInput will treat as `Cancel` (End without update newTokenValue).
* The `onTokenValuesChange` will not be called.
*
* @ return
* Type: void
*/
onEditEnd: PropTypes.func.isRequired,
/**
* A callback function, which should be `invoked` when end-user `delete` the token
*
* Note:
* Call this function to tell TokenInput to delete the token.
* As result, TokenInput will remove it, and
* TokenInput will call `onTokenValuesChange` to update tokenValues.
*
* onDelete()
*
* @ return
* Type: void
*/
onDelete: PropTypes.func.isRequired,
FAQs
A react token (tag) input component. Allow customize data structure and Look & Feel
We found that react-customize-token-input demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.