Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Added property 'fullWidth' for LinkBarSearchField
Browse files Browse the repository at this point in the history
  • Loading branch information
Dontsov-Roman committed Mar 22, 2019
1 parent c5c75de commit e3a95ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
22 changes: 15 additions & 7 deletions src/atoms/LinkBarSearchField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const AbsoluteFontIcon = styled(FontIconBase)`
const InputBase = LinkBarElementBase.withComponent('input');
const Input = styled(InputBase)`
${(props) => {
const { size, icon } = props;
const { size, icon, fullWidth } = props;
const horizontalBase = getVariable('horizontalBase')(props);
const placeholderColor = getColor(props.placeholderColor)(props);
const widthFactor = size === 'small' ? 9 : 13;
const marginFactor = size === 'small' ? 1/2 : 1;
const horizontalMargin = `calc(${marginFactor} * ${horizontalBase})`;
const width = `calc(${widthFactor} * ${horizontalBase})`;
const width = fullWidth ? `calc(100% - calc(2 * ${horizontalMargin}))` : `calc(${widthFactor} * ${horizontalBase})`;
let paddingLeft = '1rem';
if (icon) {
paddingLeft = size === 'small' ? '2.7rem' : '4.4rem';
Expand All @@ -58,21 +58,26 @@ const Input = styled(InputBase)`
`;
}}
`;

const Form = styled.form`
${({ fullWidth }) => fullWidth && css(`
width: 100%;
`)}
`
const LinkBarSearchField = ({
action,
iconColor,
inputName,
formName,
size,
icon,
fullWidth,
...rest
}) => (
<Fragment>
{icon && <AbsoluteFontIcon name={icon} size={size} textColor={iconColor} inset />}
<form id={formName} name={formName} action={action}>
<Input id={inputName} name={inputName} size={size} type="search" inset rounded required icon={icon} {...rest} />
</form>
<Form id={formName} name={formName} action={action} fullWidth={fullWidth}>
<Input id={inputName} name={inputName} size={size} type="search" inset rounded required icon={icon} fullWidth={fullWidth} {...rest} />
</Form>
</Fragment>
);
LinkBarSearchField.propTypes = {
Expand All @@ -94,8 +99,10 @@ LinkBarSearchField.propTypes = {
textColor: PropTypes.string,
/** Icon's name, for example "search", if empty(by default) icon will not render */
icon: PropTypes.string,
/** If true will change width to 100% except calculated margins, which depends on size and horizontalBase */
fullWidth: PropTypes.bool,
};
LinkBarSearchField.defaultProps ={
LinkBarSearchField.defaultProps = {
activeBackgroundColor: null,
backgroundColor: 'grayTintLighter',
iconColor: 'link',
Expand All @@ -105,6 +112,7 @@ LinkBarSearchField.defaultProps ={
size: 'medium',
textColor: 'type',
icon: "",
fullWidth: false,
};

export { LinkBarSearchField };
Expand Down
5 changes: 2 additions & 3 deletions stories/link-bar-elements/SearchFieldStory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { withInfo } from '@storybook/addon-info';
// HorizontalLinkBar
import {
HorizontalLinkBar,
LinkBarLink,
SmallLinkBarLink,
LargeLinkBarLink,
LinkBarSearchField,
Expand All @@ -21,9 +20,9 @@ const SearchFieldStory = () => (
</HorizontalLinkBar>
<div>-</div>
<HorizontalLinkBar backgroundColor="grayTintLighter">
<LinkBarLink linkText="One" url="https://example.com" isActive />
<LinkBarLink linkText="Two" url="https://example.com" />
<LinkBarSearchField
isListItem
fullWidth
placeholder="Search My Shoe"
backgroundColor="white"
/>
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8261,7 +8261,7 @@ sax@^1.2.4, sax@~1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

scheduler@^0.13.3, scheduler@^0.13.4:
scheduler@^0.13.4:
version "0.13.4"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.4.tgz#8fef05e7a3580c76c0364d2df5e550e4c9140298"
integrity sha512-cvSOlRPxOHs5dAhP9yiS/6IDmVAVxmk33f0CtTJRkmUWcb1Us+t7b1wqdzoC0REw2muC9V5f1L/w5R5uKGaepA==
Expand Down

0 comments on commit e3a95ac

Please sign in to comment.