New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@commercetools-uikit/localized-multiline-text-input

Package Overview
Dependencies
Maintainers
3
Versions
1053
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools-uikit/localized-multiline-text-input

#### Description

  • 0.0.0-canary-202061012469
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3K
increased by13.72%
Maintainers
3
Weekly downloads
 
Created
Source

LocalizedMultilineTextInput

Description

A controlled text input component for localized multi-line strings with validation states.

Usage

import { LocalizedMultilineTextInput } from '@commercetools-frontend/ui-kit';

<LocalizedMultilineTextInput
  value={{ en: 'House\nFoo', de: 'House' }}
  onChange={(event) => alert(event.target.name, event.target.value)}
/>;
Properties
PropsTypeRequiredValuesDefaultDescription
idstring---Used as prefix of HTML id property. Each input field id will have the language as a suffix (${idPrefix}.${lang}), e.g. foo.en
namestring---Used as HTML name property for each input field. Each input field name will have the language as a suffix (${namePrefix}.${lang}), e.g. foo.en
valueobject--Values to use. Keyed by language, the values are the actual values, e.g. { en: 'Horse', de: 'Pferd' }
autoCompletestring---Used as HTML autocomplete property
onChangefunction--Gets called when any input is changed. Is called with the change event of the changed input.
selectedLanguagestring--Specifies which language will be shown in case the LocalizedMultilineTextInput is collapsed.
onBlurfunction---Called when any field is blurred. Is called with the event of that field.
onFocusfunction---Called when any field is focussed. Is called with the event of that field.
defaultExpandMultilineTextbool--falseExpands input components holding multiline values instead of collpasing them by default.
hideLanguageExpansionControlsbool--falseWill hide the language expansion controls when set to true. All languages will be shown when set to true.
defaultExpandLanguagesbool--falseControls whether one or all languages are visible by default. Pass true to show all languages by default.
isAutofocussedbool--falseSets the focus on the first input when true is passed.
isDisabledbool--falseDisables all input fields.
isReadOnlybool--falseDisables all input fields and shows them in read-only mode.
placeholderobject---Placeholders for each language. Object of the same shape as value.
horizontalConstraintobject-m, l, xl, scalescaleHorizontal size limit of the input fields.
hasErrorbool---Will apply the error state to each input without showing any error message.
hasWarningbool---Will apply the warning state to each input without showing any warning message.
errorsobjectOf(node)---Used to show errors underneath the inputs of specific currencies. Pass an object whose key is a currency and whose value is the error to show for that key.
warningsobjectOf(node)---Used to show warnings underneath the inputs of specific currencies. Pass an object whose key is a currency and whose value is the warning to show for that key.

The component forwards all data attribute props. It further adds a -${language} suffix to the values of the data-test and data-track-component attributes, e.g data-test="foo" will get added to the input for en as data-test="foo-en".

Main Functions and use cases are:

  • Receiving localized input from user
Static Properties
createLocalizedString(languages, existingTranslations)

This function creates a localized string. It merges the languages and the language keys of existing translations to form a localized string holding all languages. The existingTranslations argument is optional. If it is not passed, an empty localized field will be created.

const languages = ['en', 'de'];
LocalizedMultilineTextInput.createLocalizedString(languages);
// -> { en: '', de: '' }

In case existingTranslations is passed, it will merge an empty localized field with the existing translations. Usually this is used to ensure that a localized string contains at least the project's languages.

const languages = ['en', 'de'];
const existingTranslations = { en: 'Tree', ar: 'شجرة' };
LocalizedMultilineTextInput.createLocalizedString(
  languages,
  existingTranslations
);
// -> { en: 'Tree', de: '', ar: 'شجرة' }
isEmpty(localizedField)

Returns true when all values in a localized field are empty.

LocalizedMultilineTextInput.isEmpty({});
// -> true
LocalizedMultilineTextInput.isEmpty({ en: '', de: '  ' });
// -> true
LocalizedMultilineTextInput.isEmpty({ en: 'Tree', de: '' });
// -> false
omitEmptyTranslations(localizedField)

Omits translations with empty values.

LocalizedMultilineTextInput.omitEmptyTranslations({ en: '', de: '  ' });
// -> {}
LocalizedMultilineTextInput.omitEmptyTranslations({ en: 'Tree', de: '' });
// -> { en: 'Tree' }
isTouched(touched)

Expects to be called with an object or undefined. Returns true when at least one value is truthy.

RequiredValueErrorMessage

This field exports a default error message which can be used when the field is required, but the user provided no value. You can use it as

render (
  return (
    <div>
      <LocalizedMultilineTextInput hasError={isMissing} />
      {
        isMissing && <LocalizedMultilineTextInput.RequiredValueErrorMessage />
      }
    </div>
  )
)

FAQs

Package last updated on 10 Jul 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc