Skip to content

Commit 562da59

Browse files
docs(textfield): add WithLocaleText story
1 parent 5e298d2 commit 562da59

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

components/textfield/stories/template.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,44 @@ export const KeyboardFocusTemplate = (args, context) => Container({
298298
}, context)}
299299
`
300300
}, context);
301+
302+
export const LocaleWrapper = (args, context) => {
303+
const translations = {
304+
en: {
305+
labelText: "Username",
306+
value: "john_doe",
307+
},
308+
ja: {
309+
labelText: "ユーザー名",
310+
value: "山田太郎",
311+
},
312+
zh: {
313+
labelText: "用户名",
314+
value: "张伟",
315+
},
316+
ko: {
317+
labelText: "사용자 이름",
318+
value: "김철수",
319+
},
320+
ar: {
321+
labelText: "اسم المستخدم",
322+
value: "محمد_أحمد",
323+
},
324+
he: {
325+
labelText: "שם משתמש",
326+
value: "דני123",
327+
},
328+
fa: {
329+
labelText: "نام کاربری",
330+
value: "علی_رضا",
331+
},
332+
th: {
333+
labelText: "ชื่อผู้ใช้",
334+
value: "สมชาย",
335+
},
336+
};
337+
const { lang } = context.globals;
338+
const { labelText, value } = translations[lang] ?? translations.en;
339+
340+
return Template({ ...args, labelText, value }, context);
341+
};

components/textfield/stories/textfield.stories.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { disableDefaultModes } from "@spectrum-css/preview/modes";
33
import { isDisabled, isFocused, isInvalid, isKeyboardFocused, isLoading, isQuiet, isReadOnly, isRequired, isValid, size } from "@spectrum-css/preview/types";
44
import metadata from "../metadata/metadata.json";
55
import packageJson from "../package.json";
6-
import { HelpTextOptions, KeyboardFocusTemplate, Template, TextFieldOptions } from "./template.js";
6+
import { HelpTextOptions, KeyboardFocusTemplate, LocaleWrapper, Template, TextFieldOptions } from "./template.js";
77
import { TextFieldGroup } from "./textfield.test.js";
88

99
/**
@@ -149,6 +149,9 @@ export const Default = TextFieldGroup.bind({});
149149
Default.tags = ["!autodocs"];
150150
Default.args = {};
151151

152+
export const WithLocaleText = LocaleWrapper.bind({});
153+
WithLocaleText.tags = ["!autodocs"];
154+
152155
// ********* DOCS ONLY ********* //
153156

154157
export const Standard = TextFieldOptions.bind({});

0 commit comments

Comments
 (0)