-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Locale Provider #434
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2925fc9
wip: impl locale provider
kohashi b75963e
fix: LocaleProivder wrapped
kohashi 257b054
feat: useLocaleProps function
kohashi fee6046
add: locale selection on storybook
kohashi a804263
localization: ConfirmModal
kohashi f379f39
localization: FileUploader
kohashi 7fc900a
localization: ItemEmpty
kohashi 59f80d8
chore: export
kohashi 4b8ed68
storybook:
kohashi 0d542e6
lint:
kohashi 858fc12
storybook: styling
kohashi 0565bb2
rm: remove unused styled.ts
kohashi bab1990
mv: useLocaleProps
kohashi b4ff65f
rm: no clear difference in execution speed, let/const.
kohashi a0982f6
add: export locales
kohashi 30d2803
storybook: add custom locale definition
kohashi 89d3f44
fix: extract jsx inline strings to props
kohashi 9f49cf5
feat: add l10n to filter components
kohashi a64b092
test: update snapshot
kohashi 344aa06
Merge branch 'master' of https://github.com/voyagegroup/ingred-ui int…
kohashi e871c1e
l10n: add "not found" l10n
kohashi 6db730a
rm: unused
kohashi 215ac11
fix: remove snapshot from LocaleProvider
kohashi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
src/components/LocaleProvider/LocaleProvider.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
import * as React from "react"; | ||
import { Story } from "@storybook/react/types-6-0"; | ||
import LocaleProvider, { LocaleProviderProps } from "."; | ||
import { | ||
Button, | ||
Card, | ||
ConfirmModal, | ||
MultipleFilter, | ||
Select, | ||
Spacer, | ||
ToggleButton, | ||
} from ".."; | ||
|
||
import * as locales from "../../constants/locale"; | ||
import FileUploader from "../FileUploader"; | ||
import ItemEmpty from "../ItemEmpty"; | ||
import { FilterPackType, ReferedFilterType } from "../MultipleFilter/types"; | ||
|
||
export default { | ||
title: "Components/Utils/LocaleProvider", | ||
component: LocaleProvider, | ||
}; | ||
|
||
const filterPacksExample: FilterPackType[] = [ | ||
{ | ||
categoryName: "Row name", | ||
filters: [ | ||
{ | ||
filterName: "Demand", | ||
control: { | ||
type: "text", | ||
}, | ||
}, | ||
{ | ||
filterName: "Channel", | ||
control: { | ||
type: "text", | ||
}, | ||
}, | ||
{ | ||
filterName: "Attribute", | ||
control: { | ||
type: "text", | ||
}, | ||
}, | ||
{ | ||
filterName: "Type", | ||
control: { | ||
type: "text", | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
categoryName: "Linking", | ||
filters: [ | ||
{ | ||
filterName: "Device", | ||
control: { | ||
type: "select", | ||
options: ["Not selected", "Not Linking", "Linking"], | ||
}, | ||
}, | ||
{ | ||
filterName: "Site", | ||
control: { | ||
type: "select", | ||
options: ["Not selected", "Not Linking", "Linking"], | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
categoryName: "Condition", | ||
filters: [ | ||
{ | ||
filterName: "Public", | ||
control: { | ||
type: "boolean", | ||
}, | ||
}, | ||
{ | ||
filterName: "Active", | ||
control: { | ||
type: "boolean", | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export const Example: Story<LocaleProviderProps> = (args) => { | ||
const localeOptions = Object.keys(locales).map((_) => ({ | ||
label: _, | ||
value: _, | ||
})); | ||
localeOptions.unshift({ label: "Unspecified(default behavior)", value: "" }); | ||
const [active, setActive] = React.useState<boolean>(false); | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [selectedLocale, setSelectedLocale] = React.useState(localeOptions[1]); | ||
const handleToggleButton = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const handleLocationChange = (v: { label: string; value: string }) => { | ||
setSelectedLocale(v); | ||
}; | ||
|
||
const [filters, setFilters] = React.useState<ReferedFilterType[]>([]); | ||
const handleChange = (referedFilters: ReferedFilterType[]) => { | ||
setFilters(referedFilters); | ||
}; | ||
|
||
return ( | ||
<LocaleProvider locale={locales[selectedLocale.value]}> | ||
<Spacer pl={2} pt={2} pb={4}> | ||
<div> Select a locale! </div> | ||
<Select | ||
options={localeOptions} | ||
defaultValue={selectedLocale} | ||
onChange={handleLocationChange} | ||
/> | ||
<div>Selected locale: {selectedLocale.value} </div> | ||
</Spacer> | ||
|
||
<h2>ToggleButton</h2> | ||
<Spacer pl={2} pt={2} pb={4}> | ||
<ToggleButton active={active} onChange={() => setActive(!active)} /> | ||
</Spacer> | ||
|
||
<h2>ConfirmModal</h2> | ||
<Spacer pl={2} pt={2} pb={4}> | ||
<Button onClick={handleToggleButton}>Open Modal</Button> | ||
<ConfirmModal | ||
title="ConfirmModal Test" | ||
onClose={handleToggleButton} | ||
onSubmit={() => { | ||
/** void. Code to show the footer */ | ||
}} | ||
{...args} | ||
isOpen={isOpen} | ||
> | ||
Content | ||
</ConfirmModal> | ||
</Spacer> | ||
|
||
<h2>FileUploader</h2> | ||
<Spacer pl={2} pt={2} pb={4}> | ||
<FileUploader onSelectFiles={() => {}} /> | ||
</Spacer> | ||
|
||
<h2>ItemEmpty</h2> | ||
<Spacer pl={2} pt={2} pb={4}> | ||
<ItemEmpty /> | ||
</Spacer> | ||
|
||
<h2>MultipleFilter</h2> | ||
<Spacer pl={2} pt={2} pb={40}> | ||
<MultipleFilter | ||
filterPacks={filterPacksExample} | ||
onChange={handleChange} | ||
/> | ||
</Spacer> | ||
</LocaleProvider> | ||
); | ||
}; | ||
|
||
export const CustomLocale: Story<LocaleProviderProps> = () => { | ||
const koKR: locales.Localization = { | ||
components: { | ||
ToggleButton: { | ||
defaultProps: { activeText: "온", inActiveText: "오프" }, | ||
}, | ||
}, | ||
}; | ||
const [active, setActive] = React.useState<boolean>(false); | ||
return ( | ||
<LocaleProvider locale={koKR}> | ||
<h2>Define Custom Locale</h2> | ||
<Spacer pl={2} pt={2} pb={4}> | ||
<ToggleButton active={active} onChange={() => setActive(!active)} /> | ||
</Spacer> | ||
|
||
<div>You can define a custom locale definition as follows.</div> | ||
<br /> | ||
<Card> | ||
<pre> | ||
// Custom Locale <br /> | ||
const koKR: locales.Localization = {JSON.stringify(koKR, null, 4)} | ||
<br /> | ||
<br /> | ||
// Apply to LocaleProvider <br /> | ||
{"<LocaleProvider locale={koKR}>"} | ||
</pre> | ||
</Card> | ||
</LocaleProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from "react"; | ||
import { enUS, Localization } from "../../constants/locale"; | ||
|
||
export type LocaleProviderProps = { | ||
locale?: Localization; | ||
}; | ||
|
||
export const LocaleContext = React.createContext<LocaleProviderProps>({ | ||
// Default locale | ||
locale: enUS, | ||
}); | ||
const LocaleProvider: React.FunctionComponent<LocaleProviderProps> = ({ | ||
locale, | ||
children, | ||
}) => ( | ||
<LocaleContext.Provider value={{ locale: locale }}> | ||
{children} | ||
</LocaleContext.Provider> | ||
); | ||
|
||
export default LocaleProvider; |
14 changes: 14 additions & 0 deletions
14
src/components/LocaleProvider/__tests__/LocaleProvider.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from "react"; | ||
import "@testing-library/jest-dom/extend-expect"; | ||
import { cleanup } from "@testing-library/react"; | ||
import { renderWithThemeProvider } from "../../../utils/renderWithThemeProvider"; | ||
import LocaleProvider from "../"; | ||
|
||
describe("LocaleProvider component testing", () => { | ||
afterEach(cleanup); | ||
|
||
test("LocaleProvider", () => { | ||
const { asFragment } = renderWithThemeProvider(<LocaleProvider />); | ||
expect(asFragment()).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from "./LocaleProvider"; | ||
export type { LocaleProviderProps } from "./LocaleProvider"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ItemEmpty の NotFound も
useLocaleProps
の対象にしました。