Skip to content

Input

Password input

Button with the ShowYes icon enables the password display. ShowNo hides the password and shows bullets, respectively.

tsx
import React from 'react';
import Input from 'intergalactic/input';
import ShowYesM from 'intergalactic/icon/ShowYes/m';
import ShowNoM from 'intergalactic/icon/ShowNo/m';
import { ButtonLink } from 'intergalactic/button';
import { Text } from 'intergalactic/typography';
import { Flex } from 'intergalactic/flex-box';
import { Hint } from 'intergalactic/tooltip';

const Demo = () => {
  const [type, setType] = React.useState('password');

  return (
    <Flex direction='column' gap={2}>
      <Text tag='label' htmlFor='password-example' size={200}>
        Your password
      </Text>
      <Input w={240}>
        <Input.Value
          defaultValue='I_like_cats'
          placeholder='Password'
          type={type}
          id='password-example'
        />
        <Input.Addon>
          <Hint
            title={type === 'password' ? 'Show password' : 'Hide password'}
            tag={ButtonLink}
            use='secondary'
            addonLeft={type === 'password' ? ShowYesM : ShowNoM}
            onClick={() => setType((type) => (type === 'password' ? 'text' : 'password'))}
          />
        </Input.Addon>
      </Input>
    </Flex>
  );
};

export default Demo;

Loading state

If the input is in a loading state while searching, sending, or entering data dynamically, add Spin as the right addon.

tsx
import React from 'react';
import Input from 'intergalactic/input';
import Spin from 'intergalactic/spin';
import { Text } from 'intergalactic/typography';
import { Box } from 'intergalactic/flex-box';

const Demo = () => {
  const [value, setValue] = React.useState('');
  const [loading, setLoading] = React.useState(false);

  React.useEffect(() => {
    const timer = setTimeout(() => setLoading(false), 1000);
    return () => clearTimeout(timer);
  }, [value]);

  function handlerInput(v) {
    setLoading(true);
    setValue(v);
  }

  return (
    <>
      <Text tag='label' htmlFor='loading-example' size={200}>
        Input with loading state
      </Text>
      <Box mt={2}>
        <Input w={300}>
          <Input.Value
            id='loading-example'
            placeholder='Type something to see world spinning...'
            value={value}
            onChange={handlerInput}
          />
          {loading && (
            <Input.Addon>
              <Spin size='xs' />
            </Input.Addon>
          )}
        </Input>
      </Box>
    </>
  );
};

export default Demo;

Input with clearing ability

The input field may have a Clear button inside it to clear the entered value. This button is only visible when there is some typed text or values in the input field, regardless of its status.

tsx
import React from 'react';
import Input from 'intergalactic/input';
import { ButtonLink } from 'intergalactic/button';
import CloseM from 'intergalactic/icon/Close/m';
import { Text } from 'intergalactic/typography';
import { Flex } from 'intergalactic/flex-box';
import { Hint } from 'intergalactic/tooltip';

const Demo = () => {
  const [value, setValue] = React.useState('');

  return (
    <Flex direction='column' gap={2}>
      <Text tag='label' htmlFor='clear-example' size={200}>
        Clearable input
      </Text>
      <Input w={320}>
        <Input.Value
          placeholder='Type something to clear something'
          value={value}
          onChange={(v) => setValue(v)}
          id='clear-example'
        />
        {value && (
          <Input.Addon>
            <Hint
              tag={ButtonLink}
              use='secondary'
              addonLeft={CloseM}
              title='Clear'
              onClick={() => setValue('')}
            />
          </Input.Addon>
        )}
      </Input>
    </Flex>
  );
};

export default Demo;

Input with submit button inside

You can place a submit button inside the input as the right addon. It's only visible when the input has a nonempty value.

tsx
import React from 'react';
import Input from 'intergalactic/input';
import { ButtonLink } from 'intergalactic/button';
import CheckM from 'intergalactic/icon/Check/m';
import { Text } from 'intergalactic/typography';
import { Flex } from 'intergalactic/flex-box';
import { Hint } from 'intergalactic/tooltip';

const Demo = () => {
  const [value, setValue] = React.useState('');

  return (
    <Flex direction='column' gap={2}>
      <Text tag='label' htmlFor='submit-example' size={200}>
        Input with submit button
      </Text>
      <Input w={320}>
        <Input.Value
          placeholder='Write something'
          value={value}
          onChange={setValue}
          id='submit-example'
        />
        {value && (
          <Input.Addon>
            <Hint
              tag={ButtonLink}
              addonLeft={CheckM}
              color='icon-secondary-success'
              title='Submit'
              onClick={() => setValue('')}
            />
          </Input.Addon>
        )}
      </Input>
    </Flex>
  );
};

export default Demo;

Input with text addon

You can add text to the input as an addon that the user can't modify. This can be useful when you need a fixed placeholder text in the input.

tsx
import React from 'react';
import Input from 'intergalactic/input';
import { Text } from 'intergalactic/typography';
import { Box } from 'intergalactic/flex-box';

const Demo = () => {
  return (
    <>
      <Text size={300}>Input with permanent text</Text>
      <Box mt={2} mb={4}>
        <Input size='l' w={300}>
          <Input.Addon pr='3px'>
            <Text color='text-secondary' tag='label' htmlFor='permanent-placeholder-l-example'>
              Permanent text:
            </Text>
          </Input.Addon>
          <Input.Value placeholder='Placeholder' id='permanent-placeholder-l-example' />
        </Input>
      </Box>
      <Text size={200}>Input with permanent text</Text>
      <Box mt={2}>
        <Input size='m' w={300}>
          <Input.Addon pr='2px'>
            <Text color='text-secondary' tag='label' htmlFor='permanent-placeholder-m-example'>
              Permanent text:
            </Text>
          </Input.Addon>
          <Input.Value placeholder='Placeholder' id='permanent-placeholder-m-example' />
        </Input>
      </Box>
    </>
  );
};

export default Demo;

Input with multiple addons

When stacking two addons, the indents of the adjacent addons should be divided in half. This ensures that there is enough space around them for normal interaction.

tsx
import React from 'react';
import Input from 'intergalactic/input';
import Link from 'intergalactic/link';
import CloseM from 'intergalactic/icon/Close/m';
import ShowYesM from 'intergalactic/icon/ShowYes/m';
import ShowNoM from 'intergalactic/icon/ShowNo/m';
import { Text } from 'intergalactic/typography';
import { Box } from 'intergalactic/flex-box';
import { ButtonLink } from 'intergalactic/button';
import { Hint } from 'intergalactic/tooltip';

const Demo = () => {
  const [value, setValue] = React.useState('');
  const [type, setType] = React.useState('password');

  return (
    <>
      <Text tag='label' htmlFor='2addon-example' size={200}>
        Your password
      </Text>
      <Box mt={2}>
        <Input w={320}>
          <Input.Value
            defaultValue='I_like_cats'
            type={type}
            value={value}
            onChange={(v) => setValue(v)}
            id='2addon-example'
          />
          {value && (
            <Input.Addon pl={2} pr={1}>
              <Hint
                tag={ButtonLink}
                addonLeft={CloseM}
                use='secondary'
                title='Clear'
                onClick={() => setValue('')}
              />
            </Input.Addon>
          )}
          <Input.Addon px={2}>
            <Link>Forgot?</Link>
          </Input.Addon>
          <Input.Addon>
            <Hint
              title={type === 'password' ? 'Show password' : 'Hide password'}
              tag={ButtonLink}
              use='secondary'
              addonLeft={type === 'password' ? ShowYesM : ShowNoM}
              onClick={() => setType((type) => (type === 'password' ? 'text' : 'password'))}
            />
          </Input.Addon>
        </Input>
      </Box>
    </>
  );
};

export default Demo;

Input with other component inside

You can also place a Badge or a Tag inside the input.

tsx
import React from 'react';
import Input from 'intergalactic/input';
import Badge from 'intergalactic/badge';
import Tag from 'intergalactic/tag';
import { Text } from 'intergalactic/typography';
import { Box } from 'intergalactic/flex-box';

const Demo = () => {
  const [value, setValue] = React.useState('heh');

  return (
    <div>
      <Text tag='label' htmlFor='count-example' size={200}>
        Input with symbols counter
      </Text>
      <Box mt={2} mb={4}>
        <Input w={320}>
          <Input.Value
            placeholder='Count some words right here'
            value={value}
            onChange={(v) => setValue(v)}
            maxLength={10}
            id='count-example'
            aria-describedby='chars-counter'
          />
          <Input.Addon>
            <Tag size='m' id='chars-counter'>
              {value.length}/10
            </Tag>
          </Input.Addon>
        </Input>
      </Box>
      <Text tag='label' htmlFor='badge-example' size={200}>
        Input with badge
      </Text>
      <Box mt={2}>
        <Input w={320}>
          <Input.Value placeholder='Wow! Such input. So new.' id='badge-example' />
          <Input.Addon>
            <Badge bg='green-300'>new</Badge>
          </Input.Addon>
        </Input>
      </Box>
    </div>
  );
};

export default Demo;

Released under the MIT License.

Released under the MIT License.