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

fix: ts path warning #6

Merged
merged 3 commits into from
Mar 22, 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
18 changes: 10 additions & 8 deletions packages/ui-react/lib/Input/Input.module.scss
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
@use '../variables' as *;
@use '../_variables/color.scss' as *;
$border-radius: $radius-8;
$border-width: $border-1;
$font-size-select: $font-size-14;
$font-size-label: $font-size-10;
$padding-left-right: 11px;
$padding-label-top: 8px;
$animation-duration: $duration-200;

.base {
width: fit-content;
border-radius: $border-radius;
box-sizing: border-box;
color: var(--shadow-color);
color: $gray-color;
position: relative;
transition: all $animation-duration $cubic-bezier;
font-weight: 500;
background-color: var(--white-color);
&.border {
border: $border-width solid var(--shadow-color) !important;
border: $border-width solid $gray-color !important;
&:hover:not(&.disabled) {
border: $border-width solid var(--primary-color) !important;
border: $border-width solid $primary-color !important;
}
&:has(.input:focus) {
border: $border-width solid var(--primary-color) !important;
border: $border-width solid $primary-color !important;
}
}
cursor: text;
.inputLabel {
cursor: text;
position: absolute;
transition: all $animation-duration $cubic-bezier;
top: 50%;
Expand All @@ -40,7 +41,7 @@ $animation-duration: $duration-200;
}

.input:focus ~ .inputLabel {
color: var(--primary-color) !important;
color: $primary-color !important;
top: $padding-label-top;
font-size: $font-size-label;
transform: translate(0);
Expand All @@ -53,9 +54,10 @@ $animation-duration: $duration-200;
position: relative;
top: 0;
bottom: 0;
color: var(--black-color);
color: $black-color;
box-sizing: border-box;
font-size: $font-size-select;
border-radius: $border-radius;
}
&.disabled {
@include disabled;
Expand Down
64 changes: 30 additions & 34 deletions packages/ui-react/lib/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
},
ref,
) => {
//设置isUpLabel来调节Label上浮状态
//Set isUpLabel to adjust the state of Label floating.
const [isUpInputLabel, setIsUpInputLabel] = useState<boolean>(false);
const [inputValue, setInputValue] = useState<string>(defaultValue);
const InputClass = classnames(
Expand All @@ -77,16 +77,16 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
styles[isBorder ? 'border' : ''],
);
useEffect(() => {
if (placeholder) {
setIsUpInputLabel(true);
}
placeholder && setIsUpInputLabel(true);
}, [placeholder]);
//设置,当input框里面没有内容时,placeHolder也没有内容时,将label框拉下

//Set to pull down the label box when there is no content inside the input box and no content in the placeHolder.
const blurInput = () => {
if (!inputValue && !placeholder && isUpInputLabel) {
setIsUpInputLabel(false);
}
};

const changeValue = (e: ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value);
onchange && onchange(e.target.value, e);
Expand All @@ -97,36 +97,32 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
}, [value]);

return (
<>
<div
className={InputClass}
style={{ width: `${width}px`, fontSize: `${fontsize}px` }}
onClick={() => !disabled && setIsUpInputLabel(true)}
<div
className={InputClass}
style={{ width: `${width}px`, fontSize: `${fontsize}px` }}
onClick={() => !disabled && setIsUpInputLabel(true)}
>
<input
id="input"
className={styles['input']}
ref={ref}
placeholder={placeholder}
type={mode}
disabled={disabled}
onChange={changeValue}
onBlur={blurInput}
value={inputValue}
{...rest}
/>
<label
htmlFor="input"
className={`${styles['inputLabel']} ${
inputValue || placeholder ? styles['isUpInputLabel'] : ''
}`}
>
<input
id="input"
className={styles['input']}
ref={ref}
placeholder={placeholder}
type={mode}
disabled={disabled}
onChange={changeValue}
onBlur={blurInput}
autoComplete="off"
autoSave="off"
value={inputValue}
{...rest}
/>
<label
htmlFor="input"
className={`${styles['inputLabel']} ${
inputValue || placeholder ? styles['isUpInputLabel'] : ''
}`}
>
{label}
</label>
</div>
</>
{label}
</label>
</div>
);
},
);
Expand Down
9 changes: 9 additions & 0 deletions packages/ui-react/lib/_variables/color.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$primary-color: #0078d4;
$secondary-color: #71afe5;
$danger-color: #ff0000;
$warning-color: #ffb900;
$success-color: #00c853;
$white-color: #ffffff;
$black-color: #121212;
$gray-color: #808080;
// $dark-gray-color: #dddddd;
8 changes: 4 additions & 4 deletions packages/ui-universal/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"paths": {
"@/*": ["./lib/*"]
"noFallthroughCasesInSwitch": true,
"paths": {
"@/*": ["./lib/*"]
}
},
"include": ["lib", "lib/typings/index.d.ts"]
}
Loading