简体   繁体   中英

Need to change the svg icon color in a styled DateInput

Styled DateInput from grommet . I tried changing the color this way.

const CalenderComponent = styled(DateInput)`
  svg {
    fill: #fff000 !important;
    stroke: #fff000 !important;
    path{
      fill: #fff000 !important;
      stroke: #fff000 !important;
    }
  }
`;

Component:

<CalenderComponent
  className='dateInput'
  format="mm/dd/yyyy"
></CalenderComponent>

日期输入

Code being rendered in my browser: 在此处输入图像描述

You can control the icon via inputProps of the DateInput component.

When using format prop, the icon is being rendered as part of the the input (ie MaskedInput), and the input accepts inputProps which allows icon customization as follows: inputProps={{ icon: <Calendar color="red" /> }}

Here is a fully working example:

import React from 'react';

import { Grommet, Box, DateInput } from 'grommet';
import { Calendar } from 'grommet-icons';
import { grommet } from 'grommet/themes';

export const Format = () => {
  const [value, setValue] = React.useState('');
  const onChange = event => {
    ...
  };
  return (
    <Grommet theme={grommet}>
      <Box align="center" pad="large">
        <Box width="medium">
          <DateInput
            inputProps={{ icon: <Calendar color="red" /> }}
            format="mm/dd/yyyy"
            value={value}
            onChange={onChange}
          />
        </Box>
      </Box>
    </Grommet>
  );
};

在此处输入图像描述

Note: when not using the format prop on DateInput, one could control the icon rendering via the buttonProps prop instead of inputProps , more details on the grommet's documentations .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM