Skip to content
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

chore(storybook): add maskito example #1572

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/storybook-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"test.a11y": "start-server-and-test build.watch http://localhost:6006 test-storybook"
},
"dependencies": {
"@maskito/core": "^3.2.0",
"@maskito/kit": "^3.2.0",
"lit": "^3.2.1"
},
"devDependencies": {
Expand Down
83 changes: 83 additions & 0 deletions packages/storybook-docs/src/stories/input.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* SPDX-FileCopyrightText: 2024 Siemens AG
*
* SPDX-License-Identifier: MIT
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Maskito, maskitoInitialCalibrationPlugin } from '@maskito/core';
import { maskitoNumberOptionsGenerator } from '@maskito/kit';
import type { Components } from '@siemens/ix/components';
import type { Meta, StoryObj } from '@storybook/web-components';

type Element = Components.IxInput & {
maskito?: Maskito;
};

const meta = {
title: 'Example/Input/Mask',
tags: [],
render: (args, ctx) => {
const input = document.createElement('ix-input');
input.value = args.value;

const maskito = new Maskito(input as any, {
...maskitoNumberOptionsGenerator({
decimalSeparator: ',',
thousandSeparator: '.',
precision: 2,
}),
plugins: [maskitoInitialCalibrationPlugin()],
});

ctx.args.maskito = maskito;

return input;
},
beforeEach: (ctx) => {
return () => {
ctx.args.maskito?.destroy();
};
},
args: {
value: '10000',
},
parameters: {
design: {
type: 'figma',
url: 'https://www.figma.com/design/r2nqdNNXXZtPmWuVjIlM1Q/iX-Components---Brand-Dark?node-id=225-5535&m=dev',
},
},
} satisfies Meta<Element>;

export default meta;
type Story = StoryObj<Element>;

export const Separators: Story = {
args: {
value: '1000001',
},
};

export const Precision: Story = {
render: (args, ctx) => {
const input = document.createElement('ix-input');
input.value = args.value;

const maskito = new Maskito(input as any, {
...maskitoNumberOptionsGenerator({
precision: 2,
min: 0,
}),
plugins: [maskitoInitialCalibrationPlugin()],
});

ctx.args.maskito = maskito;

return input;
},
args: {
value: '123.456',
},
};
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading