Skip to content
Open
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
6 changes: 4 additions & 2 deletions .storybook/StorybookToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const THEME_TOGGLE_LABELS = {
dark: 'Включить светлую тему',
}

export const StorybookToolbar = () => {
export const StorybookToolbar = ({ title }: { readonly title: string }) => {
const { theme, rt } = useUnistyles()
const isDark = rt.themeName === 'dark'
const ThemeIcon = isDark ? IconSun : IconMoon
Expand All @@ -24,7 +24,9 @@ export const StorybookToolbar = () => {

return (
<View style={styles.toolbar}>
<Text style={styles.title}>Storybook</Text>
<Text numberOfLines={1} style={styles.title}>
{title}
</Text>
<Pressable
accessibilityRole='button'
accessibilityLabel={THEME_TOGGLE_LABELS[isDark ? 'dark' : 'light']}
Expand Down
29 changes: 21 additions & 8 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import type { Preview } from '@storybook/react'
import { StyleSheet } from 'react-native-unistyles'
import { View } from 'react-native'
import { TooltipProvider } from '../src/components/Tooltip'

import { StorybookToolbar } from './StorybookToolbar'

const preview: Preview = {
decorators: [
(Story) => (
<>
<StorybookToolbar />
<View style={styles.container}>
<Story />
</View>
</>
),
(Story, context) => {
const componentName = context.title.substring(
context.title.lastIndexOf('/') + 1
)
const title =
componentName === context.name
? componentName
: `${componentName} · ${context.name}`

return (
<>
<StorybookToolbar title={title} />
<TooltipProvider>
<View style={styles.container}>
<Story />
</View>
</TooltipProvider>
</>
)
},
],
parameters: {
options: {
Expand Down
18 changes: 14 additions & 4 deletions design-tokens/input/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"black": {
"40": "rgba(0, 0, 0, 0.0400)",
"50": "rgba(0, 0, 0, 0.05)",
"100": "rgba(0, 0, 0, 0.1000)",
"200": "rgba(0, 0, 0, 0.2000)",
"300": "rgba(0, 0, 0, 0.3000)",
Expand Down Expand Up @@ -737,6 +738,10 @@
},
"help": { "strong": "{colors.solid.purple.600}" }
}
},
"shadow": {
"default": "{colors.alpha.black.100}",
"subtle": "{colors.alpha.black.50}"
}
}
},
Expand Down Expand Up @@ -1000,6 +1005,10 @@
},
"help": { "strong": "{colors.solid.purple.400}" }
}
},
"shadow": {
"default": "{colors.alpha.black.300}",
"subtle": "{colors.alpha.black.200}"
}
}
}
Expand Down Expand Up @@ -5213,15 +5222,16 @@
},
"dark": {
"root": {
"background": "{color.bg.surface.canvas.default}",
"color": "{color.fg.default}"
"background": "{color.bg.neutral.strong.default}",
"color": "{color.fg.inverse.default}"
}
}
},
"root": {
"maxWidth": "{dimension.size.2000}",
"maxWidth": "{dimension.size.1600}",
"gutter": "{dimension.space.100}",
"shadow": "{effects.elevation.400}",
"shadow": "0 4px 8px {color.shadow.default}",
"subtleShadow": "0 0 2px {color.shadow.subtle}",
"padding": "{dimension.space.200} {dimension.space.400}",
"borderRadius": "{dimension.borderRadius.200}"
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Input/InputText/InputText.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export function InputFields({ showInfo }: { showInfo: () => void }) {
- `floatLabel` — подпись внутри поля, поднимающаяся при фокусе или наличии
текста.
- `labelInfo` — делает постоянный `label` кнопкой с иконкой ⓘ и обработчиком
`labelInfo.onPress`. С `floatLabel` недоступен.
`labelInfo.onPress`. `labelInfo.iconRef` даёт ссылку на иконку, чтобы
привязать к ней Tooltip. С `floatLabel` недоступен.

`label` и `floatLabel` взаимоисключающие и необязательные. Без них место под
подпись не резервируется. С `floatLabel` отдельный `placeholder` появляется при
Expand Down
115 changes: 115 additions & 0 deletions src/components/Input/InputText/InputTextTooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import type { Meta, StoryObj } from '@storybook/react'
import { useRef, useState } from 'react'
import { ScrollView, View } from 'react-native'
import { StyleSheet } from 'react-native-unistyles'

import { Tooltip } from '../../Tooltip'
import { Body } from '../../Typography'

import { InputText, type InputTextProps } from './InputText'

type StoryArgs = InputTextProps & { tooltipText: string }

const InputTooltipDemo = ({ tooltipText }: Pick<StoryArgs, 'tooltipText'>) => {
const anchorRef = useRef<View>(null)
const [value, setValue] = useState('')
const [visible, setVisible] = useState(false)

return (
<ScrollView
contentContainerStyle={styles.content}
keyboardShouldPersistTaps='handled'
style={styles.root}
onScrollBeginDrag={() => setVisible(false)}
>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<View>
<InputText
autoFocus
required
accessibilityHint={tooltipText}
caption='Введите имя без сокращений'
label='Имя получателя'
labelInfo={{ iconRef: anchorRef, onPress: () => setVisible(true) }}
placeholder='Как в документе'
value={value}
onChangeText={setValue}
/>
</View>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Body>
Установите курсор в поле, затем нажмите ⓘ. Подсказка появляется над
иконкой, клавиатура остаётся открытой. Продолжите ввод.
</Body>
<Tooltip
anchorRef={anchorRef}
isVisible={visible}
position='top'
text={tooltipText}
onClose={() => setVisible(false)}
/>
</ScrollView>
)
}

const meta: Meta<StoryArgs> = {
title: 'Form Input/InputText',
tags: ['version:2.0', 'design:pending'],
component: InputText,
args: { tooltipText: 'Имя должно совпадать с документом получателя.' },
argTypes: { tooltipText: { control: 'text' } },
parameters: { controls: { include: ['theme', 'tooltipText'] } },
render: ({ tooltipText }) => <InputTooltipDemo tooltipText={tooltipText} />,
}

export default meta
export const TooltipWithKeyboard: StoryObj<StoryArgs> = {
name: 'InputText with Tooltip',
}

const styles = StyleSheet.create(({ semantic }) => ({
root: { flex: 1 },
content: { flexGrow: 1, gap: semantic.dimension.space[350] },
}))
6 changes: 5 additions & 1 deletion src/components/Input/core/InputLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export const InputLabel = ({
</>
)}
{labelInfo ? (
<View style={[styles.labelInfo, floating && styles.floatLabelInfo]}>
<View
collapsable={false}
ref={labelInfo.iconRef}
style={[styles.labelInfo, floating && styles.floatLabelInfo]}
>
<SvgUniversal
accessible={false}
source={IconInfoCircle}
Expand Down
11 changes: 10 additions & 1 deletion src/components/Input/core/__tests__/InputLabel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { render, userEvent } from '@testing-library/react-native'
import { createRef } from 'react'
import type { View } from 'react-native'

import { InputCaption, InputText, InputGroup, Password } from '../..'

Expand Down Expand Up @@ -59,11 +61,16 @@ describe('Input: подпись', () => {
'объединяет label и иконку в одну кнопку при добавлении info в $name',
async ({ Component }) => {
const onPress = jest.fn()
const iconRef = createRef<View>()
const { getByRole, getAllByRole, getByLabelText, queryByRole, rerender } =
render(<Component label='Email' testID='InputLabel' />)

rerender(
<Component label='Email' labelInfo={{ onPress }} testID='InputLabel' />
<Component
label='Email'
labelInfo={{ onPress, iconRef }}
testID='InputLabel'
/>
)

const button = getByRole('button', { name: 'Email. Подробнее' })
Expand All @@ -72,6 +79,7 @@ describe('Input: подпись', () => {
1
)
expect(button).toHaveProp('testID', 'InputLabelLabelInfo')
expect(typeof iconRef.current?.measure).toBe('function')
expect(queryByRole('text', { name: 'Email' })).toBeNull()
expect(getByLabelText('Email')).toHaveDisplayValue('')

Expand All @@ -81,6 +89,7 @@ describe('Input: подпись', () => {

rerender(<Component label='Email' testID='InputLabel' />)

expect(iconRef.current).toBeNull()
expect(queryByRole('button', { name: 'Email. Подробнее' })).toBeNull()
expect(getByLabelText('Email')).toHaveDisplayValue('')
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Input/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
TextInputProps,
TextStyle,
ViewStyle,
View,
PressableProps,
} from 'react-native'

Expand All @@ -14,6 +15,8 @@ export type InputState = 'default' | 'danger'
export type RenderTextInputArgs = TextInputProps & { inputRef: Ref<TextInput> }

export interface InputLabelInfo {
/** Ссылка на native View иконки ⓘ, например для якоря Tooltip. */
iconRef?: Ref<View>
/** Обработчик нажатия на label с иконкой ⓘ */
onPress: NonNullable<PressableProps['onPress']>
/**
Expand Down
Loading
Loading