-
Notifications
You must be signed in to change notification settings - Fork 69
Add line width setting for wizard line charts #3389
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
Open
arsen-afaunov
wants to merge
7
commits into
main
Choose a base branch
from
CHARTS-10226-add-line-width-setting-for-wizard-line-charts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d252e7e
Add line width setting for wizard line charts
arsen-afaunov 501c261
Address review issues
arsen-afaunov bf0ebcb
Address more review issues
arsen-afaunov db7fa75
Add shape settings scope tabs
arsen-afaunov b25158f
Add i18n and line width settings scopes test
arsen-afaunov 326c313
Fix line width range test
arsen-afaunov c1b4b07
Address naming issues
arsen-afaunov 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
67 changes: 0 additions & 67 deletions
67
src/ui/components/NumberFormatSettings/NumberInput/NumberInput.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,121 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {TextInput} from '@gravity-ui/uikit'; | ||
| import block from 'bem-cn-lite'; | ||
|
|
||
| import {STEP_BUTTON_DIRECTION, StepButton} from './StepButton'; | ||
|
|
||
| import './NumberInput.scss'; | ||
|
|
||
| const b = block('number-input'); | ||
|
|
||
| interface NumberInputProps { | ||
| value: number; | ||
| max?: number; | ||
| min?: number; | ||
| onChange: (value: number) => void; | ||
| qa?: string; | ||
| } | ||
|
|
||
| const NumberInput: React.FC<NumberInputProps> = ({ | ||
| value, | ||
| onChange, | ||
| max = Infinity, | ||
| min = -Infinity, | ||
| qa, | ||
| }) => { | ||
| const [internalValue, setInternalValue] = React.useState<string>(String(value)); | ||
|
|
||
| React.useEffect(() => { | ||
| setInternalValue(String(value)); | ||
| }, [value]); | ||
|
|
||
| const commitValue = React.useCallback( | ||
| (newValue: number) => { | ||
| setInternalValue(String(newValue)); | ||
| onChange(newValue); | ||
| }, | ||
| [onChange], | ||
| ); | ||
|
|
||
| const clampAndCommit = React.useCallback( | ||
| (delta = 0) => { | ||
| const parsed = parseInt(internalValue, 10); | ||
| const baseValue = Number.isNaN(parsed) ? value : parsed; | ||
| const newValue = baseValue + delta; | ||
|
|
||
| commitValue(Math.max(min, Math.min(max, newValue))); | ||
| }, | ||
| [internalValue, min, max, commitValue, value], | ||
| ); | ||
|
|
||
| const onBlur = React.useCallback( | ||
| (e: React.FocusEvent<HTMLInputElement>) => { | ||
| const relatedTarget = e.relatedTarget as HTMLElement | null; | ||
| if (relatedTarget?.closest(`.${b('input-button')}`)) { | ||
| return; | ||
| } | ||
|
|
||
| clampAndCommit(); | ||
| }, | ||
| [clampAndCommit], | ||
| ); | ||
|
|
||
| const onKeyDown = React.useCallback( | ||
| (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
| if (e.key === 'Enter') { | ||
| clampAndCommit(); | ||
| } | ||
| }, | ||
| [clampAndCommit], | ||
| ); | ||
|
|
||
| const onInput = React.useCallback((newValue: string) => { | ||
| setInternalValue(newValue); | ||
| }, []); | ||
|
|
||
| const onPlus = React.useCallback(() => clampAndCommit(1), [clampAndCommit]); | ||
|
|
||
| const onMinus = React.useCallback(() => clampAndCommit(-1), [clampAndCommit]); | ||
|
|
||
| const memorizedInputAttrs: React.InputHTMLAttributes<HTMLInputElement> = React.useMemo( | ||
| () => ({ | ||
| min: Number.isFinite(min) ? min : undefined, | ||
| max: Number.isFinite(max) ? max : undefined, | ||
| style: {textAlign: 'center'}, | ||
| }), | ||
| [min, max], | ||
| ); | ||
|
|
||
| const parsedInternal = parseInt(internalValue, 10); | ||
| const isMinusDisabled = !Number.isNaN(parsedInternal) && parsedInternal <= min; | ||
| const isPlusDisabled = !Number.isNaN(parsedInternal) && parsedInternal >= max; | ||
|
|
||
| return ( | ||
| <div className={b({})}> | ||
| <StepButton | ||
| direction={STEP_BUTTON_DIRECTION.Minus} | ||
| disabled={isMinusDisabled} | ||
| onClick={onMinus} | ||
| /> | ||
| <TextInput | ||
| qa={qa} | ||
| type="number" | ||
| pin="brick-brick" | ||
| controlProps={memorizedInputAttrs} | ||
| value={internalValue} | ||
| onBlur={onBlur} | ||
| onUpdate={onInput} | ||
| onKeyDown={onKeyDown} | ||
| className={b('text-input')} | ||
| /> | ||
| <StepButton | ||
| direction={STEP_BUTTON_DIRECTION.Plus} | ||
| disabled={isPlusDisabled} | ||
| onClick={onPlus} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default NumberInput; |
This file contains hidden or 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,43 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {Minus, Plus} from '@gravity-ui/icons'; | ||
| import {Button, Icon} from '@gravity-ui/uikit'; | ||
| import block from 'bem-cn-lite'; | ||
| import type {ValueOf} from 'shared'; | ||
|
|
||
| import './NumberInput.scss'; | ||
|
|
||
| const b = block('number-input'); | ||
|
|
||
| export const STEP_BUTTON_DIRECTION = { | ||
| Plus: '+', | ||
| Minus: '-', | ||
| } as const; | ||
|
|
||
| export type StepButtonDirection = ValueOf<typeof STEP_BUTTON_DIRECTION>; | ||
|
|
||
| interface StepButtonProps { | ||
| direction: StepButtonDirection; | ||
| disabled: boolean; | ||
| onClick: () => void; | ||
| } | ||
|
|
||
| const DIRECTION_CONFIG: Record< | ||
| StepButtonDirection, | ||
| {icon: typeof Plus | typeof Minus; pin: 'brick-round' | 'round-brick'} | ||
| > = { | ||
| [STEP_BUTTON_DIRECTION.Plus]: {icon: Plus, pin: 'brick-round'}, | ||
| [STEP_BUTTON_DIRECTION.Minus]: {icon: Minus, pin: 'round-brick'}, | ||
| }; | ||
|
|
||
| export const StepButton: React.FC<StepButtonProps> = ({direction, disabled, onClick}) => { | ||
| const {icon, pin} = DIRECTION_CONFIG[direction]; | ||
|
|
||
| return ( | ||
| <div className={b('input-button')}> | ||
| <Button view="outlined" pin={pin} width="max" disabled={disabled} onClick={onClick}> | ||
| <Icon data={icon} /> | ||
| </Button> | ||
| </div> | ||
| ); | ||
| }; |
Oops, something went wrong.
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.
what if title is an empty string (or null)? Is everything going to be okay?