Skip to content

Commit

Permalink
feat(clayui.com): Add Localized Input Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kresimir-coko committed Apr 10, 2020
1 parent 0c43ae6 commit fef5339
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
35 changes: 35 additions & 0 deletions clayui.com/content/docs/components/text-input-localizable.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: 'Localizable Input'
description: 'A text input variation used in fields that can be translated into multiple languages.'
lexiconDefinition: 'https://liferay.design/lexicon/core-components/forms/text-input-localizable/'
packageNpm: '@clayui/localized-input'
sibling: 'docs/components/forms/css-text-input-localizable.html'
---

<div class="nav-toc-absolute">
<div class="nav-toc">

- [Usages](#usages)
- [Basic Usage](#basic-usage)
- [Localizable URL](#localizable-url)
- [API](#api)

</div>
</div>

import {
LocalizableInput,
LocalizableInputWithURL,
} from '../../../src/components/clay/LocalizableInput';

## Basic usage

<LocalizableInput />

## Localizable URL

<LocalizableInputWithURL />

## API

<div>[APITable "clay-localized-input/src/index.tsx"]</div>
131 changes: 131 additions & 0 deletions clayui.com/src/components/clay/LocalizableInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: BSD-3-Clause
*/

import ClayLocalizedInput from '@clayui/localized-input';
import React, {useState} from 'react';

import Editor from './Editor';

const spritemap = '/images/icons/icons.svg';

const localizableInputImports = `import ClayLocalizedInput from '@clayui/localized-input';
import React from 'react';`;

const localizableInputCode = `const Component = () => {
const locales = [
{
label: 'en-US',
symbol: 'en-us',
},
{
label: 'es-ES',
symbol: 'es-es',
},
{
label: 'fr-FR',
symbol: 'fr-fr',
},
{
label: 'hr-HR',
symbol: 'hr-hr',
},
];
const [selectedLocale, setSelectedLocale] = useState(locales[0]);
const [translations, setTranslations] = useState({
'en-US': 'Apple',
'es-ES': 'Manzana',
});
return (
<ClayLocalizedInput
id="locale1"
locales={locales}
onSelectedLocaleChange={setSelectedLocale}
onTranslationsChange={setTranslations}
selectedLocale={selectedLocale}
translations={translations}
/>
)
};
render(<Component />);`;

export const LocalizableInput = () => {
const scope = {
ClayLocalizedInput,
spritemap,
useState,
};

return (
<Editor
code={localizableInputCode}
imports={localizableInputImports}
scope={scope}
/>
);
};

const localizableInputWithURLCode = `const Component = () => {
const locales = [
{
label: 'en-US',
symbol: 'en-us',
},
{
label: 'es-ES',
symbol: 'es-es',
},
{
label: 'fr-FR',
symbol: 'fr-fr',
},
{
label: 'hr-HR',
symbol: 'hr-hr',
},
];
const [selectedLocale, setSelectedLocale] = useState(locales[0]);
const [translations, setTranslations] = useState({
'en-US': 'Apple',
'es-ES': 'Manzana',
});
const prepend = '/home/';
return (
<ClayLocalizedInput
id="locale2"
label="As a URL"
locales={locales}
onSelectedLocaleChange={setSelectedLocale}
onTranslationsChange={setTranslations}
prependContent={prepend}
resultFormatter={val => "https://liferay.com" + prepend + val}
selectedLocale={selectedLocale}
translations={translations}
/>
)
};
render(<Component />);`;

export const LocalizableInputWithURL = () => {
const scope = {
ClayLocalizedInput,
spritemap,
useState,
};

return (
<Editor
code={localizableInputWithURLCode}
imports={localizableInputImports}
scope={scope}
/>
);
};

0 comments on commit fef5339

Please sign in to comment.