Skip to content

Commit

Permalink
added multiple input number
Browse files Browse the repository at this point in the history
  • Loading branch information
sabato-galasso committed Dec 5, 2023
1 parent 01bf981 commit dda8a47
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import React, {
} from 'react';
import isNumber from 'is-number';

//Custom styles
import "./assets/css/custom.css";

import { InputContainer } from './InputContainer';
import { Icon } from '../Icon/Icon';
import {
Expand Down
3 changes: 3 additions & 0 deletions src/Input/assets/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.input-number-currency > label, .input-number-percentage > label{
left: 1rem!important;
}
21 changes: 18 additions & 3 deletions stories/Form/Input.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint jsx-a11y/anchor-is-valid: 0 */
import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, useRef, useEffect } from 'react';

import { components } from 'react-select';
import AsyncSelect from 'react-select/async';
Expand Down Expand Up @@ -493,7 +493,7 @@ export const InputNumericoPercentuale = () => {

return (
<Input
addon='true'
addon={true}
addonText='%'
type='number'
label='Percentage'
Expand All @@ -510,14 +510,29 @@ export const InputNumericoPercentuale = () => {

export const InputNumericoRidimensionamento = () => {
const [value, setValue] = useState('100');
const ref = useRef(null);
const [width, setWidth] = useState('100');

useEffect(() => {
if (ref.current.classList.contains('input-number-adaptive')) {
if(!value){
setWidth(`calc(10px)`)
}else{
setWidth(`calc(40px + ${value.length}ch)`)
}
}
}, [value]);

return (
<Input
innerRef={ref}
type='number'
label='Ridimensionamento'
style={{ width }}
value={value}
placeholder={'0'}
min={0}
max={9999}
max={99999999999}
className={'input-number-adaptive'}
onChange={(ev) => {
setValue(ev.target.value);
Expand Down

0 comments on commit dda8a47

Please sign in to comment.