@kvell-group/ui 1.19.14 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@kvell-group/ui",
3
3
  "author": "Kvell Group",
4
4
  "private": false,
5
- "version": "1.19.14",
5
+ "version": "1.21.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/kvell-group/ui.git"
@@ -0,0 +1,35 @@
1
+ .root {
2
+ margin-bottom: 0.5rem;
3
+
4
+ &::after {
5
+ content: '–';
6
+ order: 1;
7
+ width: rem(12px);
8
+ text-align: center;
9
+ color: var(--color-text-base-tertiary);
10
+ font-size: var(--mantine-font-size-md);
11
+ line-height: var(--mantine-line-height-md);
12
+ }
13
+
14
+ &[data-no-separator]::after {
15
+ content: none;
16
+ }
17
+ }
18
+
19
+ .pinInput {
20
+ width: rem(42px);
21
+ }
22
+
23
+ .input {
24
+ --input-bd: var(--color-border-action-normal);
25
+ --input-color: var(--color-text-base-primary);
26
+ --input-disabled-bg: var(--color-background-input-disabled);
27
+ --input-disabled-color: var(--color-text-base-quaternary);
28
+
29
+ --input-height: 2.5rem;
30
+ --input-size: 2.5rem;
31
+
32
+ height: 2.5rem;
33
+ min-height: 2.5rem;
34
+ box-shadow: var(--mantine-shadow-xs);
35
+ }
@@ -0,0 +1,55 @@
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+
3
+ import { KvellUiProvider } from '@/components/KvellUiProvider'
4
+
5
+ import { theme } from '@/theme'
6
+ import { OtpInput as OtpInputComponent } from '@/components/Inputs/OtpInput'
7
+
8
+ const meta = {
9
+ title: 'Components/Inputs/OtpInput',
10
+ component: OtpInputComponent,
11
+ decorators: (Story) => (
12
+ <KvellUiProvider theme={theme}>
13
+ <div style={{ maxWidth: '465px' }}>
14
+ <Story />
15
+ </div>
16
+ </KvellUiProvider>
17
+ ),
18
+ } satisfies Meta<typeof OtpInputComponent>
19
+
20
+ type Story = StoryObj<typeof OtpInputComponent>
21
+
22
+ export const OtpInput: Story = {}
23
+
24
+ export const OtpInputError: Story = {
25
+ args: {
26
+ error: 'Неверный код',
27
+ },
28
+ }
29
+
30
+ export const OtpInputDisabled: Story = {
31
+ args: {
32
+ disabled: true,
33
+ },
34
+ }
35
+
36
+ export const OtpInputWithoutSeparator: Story = {
37
+ args: {
38
+ separatorIndex: 0,
39
+ },
40
+ }
41
+
42
+ export const OtpInputFourDigits: Story = {
43
+ args: {
44
+ length: 4,
45
+ },
46
+ }
47
+
48
+ export const OtpInputEightDigits: Story = {
49
+ args: {
50
+ length: 8,
51
+ separatorIndex: 4,
52
+ },
53
+ }
54
+
55
+ export default meta
@@ -0,0 +1,90 @@
1
+ import { forwardRef } from 'react'
2
+ import type { ReactNode } from 'react'
3
+ import { Input, PinInput, getStyleObject, useMantineTheme } from '@mantine/core'
4
+ import type { PinInputProps } from '@mantine/core'
5
+ import clsx from 'clsx'
6
+
7
+ import classes from './OtpInput.module.css'
8
+ import textClasses from '../../../styles/typography.module.css'
9
+ import inputBaseClasses from '../@styles/input-base.module.css'
10
+
11
+ const DEFAULT_LENGTH = 6
12
+ const DEFAULT_SEPARATOR_INDEX = 3
13
+
14
+ const inputClassName = clsx(
15
+ classes.input,
16
+ textClasses['body-m-regular'],
17
+ inputBaseClasses['input-base']
18
+ )
19
+
20
+ export type OtpInputProps = Omit<PinInputProps, 'error'> & {
21
+ error?: ReactNode
22
+ separatorIndex?: number
23
+ }
24
+
25
+ export const OtpInput = forwardRef<HTMLInputElement, OtpInputProps>((props, ref) => {
26
+ const {
27
+ error,
28
+ length = DEFAULT_LENGTH,
29
+ separatorIndex = length === DEFAULT_LENGTH ? DEFAULT_SEPARATOR_INDEX : 0,
30
+ size = 'sm',
31
+ gap = 4,
32
+ radius = 'xl',
33
+ inputMode = 'numeric',
34
+ type = 'number',
35
+ placeholder = '0',
36
+ getInputProps,
37
+ classNames,
38
+ ...restProps
39
+ } = props
40
+
41
+ const theme = useMantineTheme()
42
+
43
+ const hasSeparator = separatorIndex > 0 && separatorIndex < length
44
+
45
+ return (
46
+ <Input.Wrapper
47
+ error={error}
48
+ classNames={{ error: inputBaseClasses['error-message'] }}
49
+ >
50
+ <PinInput
51
+ ref={ref}
52
+ {...restProps}
53
+ length={length}
54
+ size={size}
55
+ gap={gap}
56
+ radius={radius}
57
+ inputMode={inputMode}
58
+ type={type}
59
+ placeholder={placeholder}
60
+ error={Boolean(error)}
61
+ classNames={(...args) => {
62
+ const custom = typeof classNames === 'function' ? classNames(...args) : classNames
63
+
64
+ return {
65
+ ...custom,
66
+ root: clsx(classes.root, custom?.root),
67
+ pinInput: clsx(classes.pinInput, custom?.pinInput),
68
+ input: clsx(inputClassName, custom?.input),
69
+ }
70
+ }}
71
+ data-no-separator={hasSeparator ? undefined : ''}
72
+ getInputProps={(index) => {
73
+ const custom = getInputProps?.(index)
74
+
75
+ return {
76
+ ...custom,
77
+ style: {
78
+ '--input-padding': '0',
79
+ '--input-text-align': 'center',
80
+ ...getStyleObject(custom?.style, theme),
81
+ order: hasSeparator && index >= separatorIndex ? 2 : 0,
82
+ },
83
+ }
84
+ }}
85
+ />
86
+ </Input.Wrapper>
87
+ )
88
+ })
89
+
90
+ OtpInput.displayName = 'OtpInput'
@@ -0,0 +1,2 @@
1
+ export { OtpInput } from './OtpInput'
2
+ export type { OtpInputProps } from './OtpInput'
@@ -0,0 +1,71 @@
1
+ .root {
2
+ --sc-padding-sm: rem(5px) rem(10px);
3
+ --sc-padding-md: rem(9px) rem(12px);
4
+ --sc-padding-lg: rem(11px) rem(14px);
5
+ --sc-color: var(--mantine-primary-color-filled);
6
+ --sc-label-color: var(--color-text-base-inverted);
7
+ --separator-color: var(--color-border-action-normal);
8
+
9
+ padding: 0;
10
+ border: rem(1px) solid var(--color-border-action-normal);
11
+ border-radius: var(--mantine-radius-xl);
12
+ background-color: var(--mantine-color-white);
13
+ box-shadow: var(--mantine-shadow-xs);
14
+
15
+ &:has(.label[data-active]:not([data-disabled], [data-read-only]):hover) {
16
+ --sc-color: var(--mantine-primary-color-filled-hover);
17
+ }
18
+
19
+ &:has(.input:disabled:checked) {
20
+ --sc-color: var(--color-background-button-primary-disabled);
21
+ }
22
+ }
23
+
24
+ .control {
25
+ --separator-color: var(--color-border-action-normal);
26
+ }
27
+
28
+ .indicator {
29
+ border-radius: 0;
30
+ box-shadow: none;
31
+ }
32
+
33
+ .label {
34
+ border-radius: 0;
35
+ font-family: var(--mantine-font-family);
36
+ font-weight: 500;
37
+ font-size: var(--mantine-font-size-caption-l);
38
+ line-height: var(--mantine-line-height-caption-l);
39
+ letter-spacing: var(--mantine-spacing-caption-l);
40
+ color: var(--color-text-base-secondary);
41
+
42
+ @media (hover: hover) {
43
+ &:where(:not([data-disabled], [data-active], [data-read-only])):hover {
44
+ background-color: var(--color-background-surface-neutral);
45
+ color: var(--color-text-base-secondary);
46
+ }
47
+ }
48
+
49
+ &[data-active] {
50
+ color: var(--color-text-base-inverted);
51
+ }
52
+
53
+ &[data-disabled] {
54
+ color: var(--color-text-base-quaternary);
55
+ }
56
+ }
57
+
58
+ .root[data-size='lg'] .label {
59
+ font-size: var(--mantine-font-size-body-s);
60
+ line-height: var(--mantine-line-height-body-s);
61
+ letter-spacing: var(--mantine-spacing-body-s);
62
+ }
63
+
64
+ .label[data-active]::before {
65
+ border-radius: 0;
66
+ }
67
+
68
+ .input:focus-visible + .label {
69
+ --segmented-control-outline: none;
70
+ box-shadow: inset 0 0 0 rem(2px) var(--color-border-action-focus-light);
71
+ }
@@ -0,0 +1,62 @@
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+
3
+ import { KvellUiProvider } from '@/components/KvellUiProvider'
4
+
5
+ import { theme } from '@/theme'
6
+ import { SegmentedControl as SegmentedControlComponent } from '@/components/Inputs/SegmentedControl'
7
+
8
+ const data = [
9
+ { value: 'card', label: 'На карту' },
10
+ { value: 'sbp', label: 'Через СБП' },
11
+ ]
12
+
13
+ const meta = {
14
+ title: 'Components/Inputs/SegmentedControl',
15
+ component: SegmentedControlComponent,
16
+ decorators: (Story) => (
17
+ <KvellUiProvider theme={theme}>
18
+ <div style={{ maxWidth: '465px' }}>
19
+ <Story />
20
+ </div>
21
+ </KvellUiProvider>
22
+ ),
23
+ args: {
24
+ data,
25
+ defaultValue: 'sbp',
26
+ fullWidth: true,
27
+ },
28
+ } satisfies Meta<typeof SegmentedControlComponent>
29
+
30
+ type Story = StoryObj<typeof SegmentedControlComponent>
31
+
32
+ export const SegmentedControl: Story = {}
33
+
34
+ export const SegmentedControlFirstSelected: Story = {
35
+ args: { defaultValue: 'card' },
36
+ }
37
+
38
+ export const SegmentedControlSizeSm: Story = {
39
+ args: { size: 'sm' },
40
+ }
41
+
42
+ export const SegmentedControlSizeLg: Story = {
43
+ args: { size: 'lg' },
44
+ }
45
+
46
+ export const SegmentedControlDisabled: Story = {
47
+ args: { disabled: true },
48
+ }
49
+
50
+ export const SegmentedControlThreeItems: Story = {
51
+ args: {
52
+ data: [...data, { value: 'wallet', label: 'Кошелёк' }],
53
+ },
54
+ }
55
+
56
+ export const SegmentedControlOneItemDisabled: Story = {
57
+ args: {
58
+ data: [...data, { value: 'wallet', label: 'Кошелёк', disabled: true }],
59
+ },
60
+ }
61
+
62
+ export default meta
@@ -0,0 +1,10 @@
1
+ import { SegmentedControl as MantineSegmentedControl } from '@mantine/core'
2
+
3
+ import classNames from './SegmentedControl.module.css'
4
+
5
+ export const SegmentedControl = MantineSegmentedControl.withProps({
6
+ size: 'md',
7
+ radius: 'xl',
8
+ withItemsBorders: true,
9
+ classNames,
10
+ })
@@ -0,0 +1 @@
1
+ export { SegmentedControl } from './SegmentedControl'
package/src/index.ts CHANGED
@@ -19,6 +19,8 @@ export { Textarea } from './components/Inputs/Textarea'
19
19
  export { DatesProvider } from './components/DatesProvider'
20
20
  export * from './components/Inputs/DatePickerInput'
21
21
  export { PinInput } from './components/Inputs/PinInput'
22
+ export { OtpInput } from './components/Inputs/OtpInput'
23
+ export { SegmentedControl } from './components/Inputs/SegmentedControl'
22
24
  export * from './components/Notifications'
23
25
 
24
26
  //components
@@ -1,4 +1,4 @@
1
- import { colorsTuple, type MantineThemeOverride } from '@mantine/core'
1
+ import { colorsTuple, defaultVariantColorsResolver, type MantineThemeOverride } from '@mantine/core'
2
2
  import { Notification } from '../components/Notifications/Notification'
3
3
  import { CloseButton } from '../components/CloseButton'
4
4
 
@@ -59,23 +59,10 @@ export const theme: MantineThemeOverride = {
59
59
  },
60
60
  primaryShade: 6, // { light: 6, dark: 8 } default mantine by theme
61
61
  primaryColor: 'primary',
62
- /* variantColorResolver: ({ color, variant, gradient, theme }) => {
63
- if (variant === 'primary') {
64
- return {
65
- background: 'var(--mantine-color-red-9)',
66
- hover: 'var(--mantine-color-red-8)',
67
- color: 'var(--mantine-color-white)',
68
- border: 'none',
69
- }
70
- }
71
-
72
- return {
73
- background: 'var(--mantine-color-red-9)',
74
- hover: 'var(--mantine-color-red-8)',
75
- color: 'var(--mantine-color-white)',
76
- border: 'none',
77
- }
78
- }, //color by variant */
62
+ variantColorResolver: (input) =>
63
+ defaultVariantColorsResolver(
64
+ input.variant === 'primary' ? { ...input, variant: 'filled' } : input
65
+ ),
79
66
  autoContrast: false, //default value
80
67
  luminanceThreshold: 0.3, //default value
81
68
  fontFamily: 'Onest, Arial, Helvetica, sans-serif',