Skip to content

Commit

Permalink
Merge pull request #46 from transifex/react-no-source-lang
Browse files Browse the repository at this point in the history
Remove source lang from React LanguagePicker
  • Loading branch information
Nikos Vasileiou authored Feb 18, 2021
2 parents 9c4d08b + 0928b69 commit a052585
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 17 deletions.
4 changes: 0 additions & 4 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ function App () {

Accepts properties:

- `sourceLanguage`: defaults to `{code: 'en', name: 'English'}`
- `className`: The CSS class that will be applied to the `<select>` tag

If you want something different than a `<select>`, it should be easy to write
Expand All @@ -191,9 +190,6 @@ function MyLanguagePicker () {

return (
<>
<button onClick={() => tx.setCurrentLocale('en')}>
English
</button>
{languages.map(({ code, name }) => (
<button key={code} onClick={() => tx.setCurrentLocale(code)}>
{name}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"node": ">=10.0.0"
},
"peerDependencies": {
"@transifex/native": "^0.7.0 || ^0.8.0 || ^0.9.0",
"@transifex/native": "^0.9.0",
"prop-types": "^15.0.0",
"react": "^16.0.0 || ^17.0.0"
},
Expand Down
11 changes: 1 addition & 10 deletions packages/react/src/components/LanguagePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ import useLanguages from '../hooks/useLanguages';
/* Component to render a language picker. Language options will be fetched
* asynchronously. Accepts props:
*
* - sourceLanguage: an object with 'code' and 'name' fields, defaults to
* `{code: 'en', name: 'English'}`
*
* - className: the CSS class to use on the <select> tag */

export default function LanguagePicker({ sourceLanguage, className }) {
export default function LanguagePicker({ className }) {
const languages = useLanguages();

return (
<select
className={className}
onChange={(e) => tx.setCurrentLocale(e.target.value)}
>
<option value={sourceLanguage.code}>{sourceLanguage.name}</option>
{languages.map(({ name, code }) => (
<option key={code} value={code}>{name}</option>
))}
Expand All @@ -30,14 +26,9 @@ export default function LanguagePicker({ sourceLanguage, className }) {
}

LanguagePicker.propTypes = {
sourceLanguage: (
PropTypes
.shape({ name: PropTypes.string, code: PropTypes.string })
),
className: PropTypes.string,
};

LanguagePicker.defaultProps = {
sourceLanguage: { code: 'en', name: 'English' },
className: '',
};
1 change: 0 additions & 1 deletion packages/react/src/hooks/useLanguages.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { tx } from '@transifex/native';
*
* return (
* <select onChange={ (e) => tx.setCurrentLocale(e.target.value) }>
* <option value='en'>English</option>
* { languages.map(({code, name}) => (
* <option key={ code } value={ code }>{ name }</option>
* )) }
Expand Down
1 change: 0 additions & 1 deletion packages/react/tests/LanguagePicker.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ afterEach(() => {
test('display language picker', async () => {
render(<LanguagePicker />);
await waitFor(() => screen.getByText('Greek'));
expect(screen.queryByText('English')).toBeTruthy();
expect(screen.queryByText('Greek')).toBeTruthy();
expect(screen.queryByText('French')).toBeTruthy();
});
Expand Down

0 comments on commit a052585

Please sign in to comment.