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

Q-67: fix states and props receiver in Input component #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
23 changes: 9 additions & 14 deletions src/Input/Input.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import atomize from '@quarkly/atomize';
import { Box } from '@quarkly/widgets';
import { useOverrides } from '@quarkly/components';
import { effects, propInfo, defaultProps, overrides } from './props';
import { propInfo, defaultProps, overrides } from './props';
import { useUniqueId } from '../utils';
import InnerInput from './components/InnerInput';
import useFormField from '../Form/hooks/useFormField';

const Input = atomize.input({
effects,
});

const InputComponent = ({
name,
type,
Expand All @@ -20,7 +16,7 @@ const InputComponent = ({
required,
disabled,
list: listFromProps,
maxlength: maxlengthFromProps,
maxLength: maxLengthFromProps,
pattern,
min,
max,
Expand All @@ -31,9 +27,9 @@ const InputComponent = ({
const { override, rest } = useOverrides(props, overrides);
const id = useUniqueId();

const maxlength = useMemo(() => {
return parseInt(maxlengthFromProps, 10);
}, [maxlengthFromProps]);
const maxLength = useMemo(() => {
return parseInt(maxLengthFromProps, 10);
}, [maxLengthFromProps]);

const list = useMemo(() => {
return listFromProps.length > 0 ? listFromProps.split(',') : [];
Expand Down Expand Up @@ -68,7 +64,7 @@ const InputComponent = ({

return (
<Box display="inline-block" {...rest}>
<Input
<InnerInput
name={name}
type={type}
placeholder={placeholder}
Expand All @@ -82,8 +78,8 @@ const InputComponent = ({
autoFocus={autoFocus}
autoComplete={autoComplete ? 'on' : 'off'}
list={list.length > 0 ? `datalist-for-input-${id}` : undefined}
maxlength={maxlength > 0 ? maxlength : undefined}
{...override('Input')}
maxLength={maxLength > 0 ? maxLength : undefined}
{...override('InnerInput')}
/>
{list.length > 0 && (
<datalist id={`datalist-for-input-${id}`}>
Expand All @@ -103,7 +99,6 @@ Object.assign(InputComponent, {
en: 'Input element',
ru: 'Элемент Input',
},
effects,
propInfo,
defaultProps,
overrides,
Expand Down
44 changes: 44 additions & 0 deletions src/Input/components/InnerInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import atomize from '@quarkly/atomize';

export default atomize.input(
{
name: 'InnerInput',
description: {
en: 'Input element',
ru: 'Input element',
},
effects: {
hover: ':hover',
focus: ':focus',
required: ':required',
placeholder: '::placeholder',
invalid: ':invalid',
disabled: ':disabled',
firstChild: ':first-child',
lastChild: ':last-child',
onlyChild: ':only-child',
firstOfType: ':first-of-type',
lastOfType: ':last-of-type',
onlyOfType: ':only-of-type',
},
propInfo: {},
useAliases: false,
CheerlessCloud marked this conversation as resolved.
Show resolved Hide resolved
},
{
as: 'input',
defaultValue: '',
'focus-border-color': '--color-lightD1',
'box-sizing': 'border-box',
'border-width': '2px',
'border-style': 'solid',
'border-color': '--color-lightD2',
'border-radius': '2px',
'padding-top': '6px',
'padding-bottom': '6px',
'padding-left': '16px',
'padding-right': '16px',
font: '--base',
color: '--dark',
outline: 'none',
}
);
14 changes: 0 additions & 14 deletions src/Input/props/effects.js

This file was deleted.

1 change: 0 additions & 1 deletion src/Input/props/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { default as effects } from './effects';
export { default as propInfo } from './propsInfo';
export { default as defaultProps } from './propsDefault';
export { default as overrides } from './overrides';
4 changes: 2 additions & 2 deletions src/Input/props/overrides.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
Input: {
kind: 'Input',
InnerInput: {
kind: 'InnerInput',
props: {
width: '100%',
padding: '6px 16px',
Expand Down
2 changes: 1 addition & 1 deletion src/Input/props/propsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default {
category: 'Text',
weight: 0.5,
},
maxlength: {
maxLength: {
title: 'Max length',
description: {
en: 'The maximum number of characters allowed in the text',
Expand Down