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

🔍 Feature/scmi 106973/right addon no borders #2651

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
22 changes: 22 additions & 0 deletions components/atom/input/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,27 @@ const BorderlessDemo = () => {
)
}

const LabelDemo = () => {
return (
<Article>
<H2>Label</H2>
<Paragraph>
Input can be used with a label using the <Code>label</Code> prop.
</Paragraph>
<Grid cols={2} gutter={[8, 8]}>
<Cell>
<Label>Right Label</Label>
<AtomInput rightLabel="m2" />
</Cell>
<Cell>
<Label>Left Label</Label>
<AtomInput leftLabel="m2" />
</Cell>
</Grid>
</Article>
)
}

const StateDemo = () => {
return (
<Article>
Expand Down Expand Up @@ -603,6 +624,7 @@ const Demo = () => (
<br />
<SizeDemo />
<br />
<LabelDemo />
<DisabledReadOnlyDemo />
<br />
<AddonAndIconDemo />
Expand Down
10 changes: 9 additions & 1 deletion components/atom/input/src/Input/Component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const Input = forwardRef(
state,
type,
value,
leftLabel,
rightLabel,
charsSize,
tabIndex,
ariaLabel,
Expand Down Expand Up @@ -88,7 +90,9 @@ const Input = forwardRef(
readOnly,
errorState,
state,
shape
shape,
leftLabel,
rightLabel
})

return (
Expand Down Expand Up @@ -204,6 +208,10 @@ Input.propTypes = {
inputMode: PropTypes.string,
/** Sets the shape of the input field. It can be 'rounded', 'square' or 'circle' */
shape: PropTypes.oneOf(Object.values(INPUT_SHAPES)),
/** Text to be rendered inside the component */
leftLabel: PropTypes.string,
/** Text to be rendered inside the component */
rightLabel: PropTypes.string,
/** Nodes to be rendered inside the component */
children: PropTypes.node
}
Expand Down
8 changes: 8 additions & 0 deletions components/atom/input/src/Input/Component/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ $class-read-only: '#{$base-class-input}--readOnly';
width: inherit;
}

&-right-label {
border-right: none;
}

&-left-label {
border-left: none;
}

&--hidden {
display: none;
}
Expand Down
30 changes: 27 additions & 3 deletions components/atom/input/src/Input/Wrappers/Addons/InputAddons.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@ import PropTypes from 'prop-types'
import {INPUT_SHAPES, SIZES} from '../../../config.js'
import {ADDON_TYPES, BASE_CLASS_ADDON_WRAPPER, getClassName} from './config.js'

const InputAddon = ({leftAddon, rightAddon, shape, size, children}) => {
if (!(leftAddon || rightAddon)) {
const InputAddon = ({
leftAddon,
rightAddon,
rightLabel,
leftLabel,
shape,
size,
children
}) => {
if (!(leftAddon || rightAddon || rightLabel || leftLabel)) {
return children
}
return (
<div
className={cx(
BASE_CLASS_ADDON_WRAPPER,
shape && `${BASE_CLASS_ADDON_WRAPPER}-shape-${shape}`,
size && `${BASE_CLASS_ADDON_WRAPPER}-size-${size}`
size && `${BASE_CLASS_ADDON_WRAPPER}-size-${size}`,
rightLabel && `${BASE_CLASS_ADDON_WRAPPER}-right-label`,
leftLabel && `${BASE_CLASS_ADDON_WRAPPER}-left-label`
)}
>
{leftLabel && (
<span className={getClassName({type: ADDON_TYPES.LEFT_LABEL, shape})}>
{leftLabel}
</span>
)}
{leftAddon && (
<span className={getClassName({type: ADDON_TYPES.LEFT, shape})}>
{leftAddon}
Expand All @@ -27,6 +42,11 @@ const InputAddon = ({leftAddon, rightAddon, shape, size, children}) => {
{rightAddon}
</span>
)}
{rightLabel && (
<span className={getClassName({type: ADDON_TYPES.RIGHT_LABEL, shape})}>
{rightLabel}
</span>
)}
</div>
)
}
Expand All @@ -36,8 +56,12 @@ InputAddon.propTypes = {
children: PropTypes.node,
/* Left addon component, text,... */
leftAddon: PropTypes.any,
/* Left label component, text,... */
leftLabel: PropTypes.any,
/* Right addon component, text,... */
rightAddon: PropTypes.any,
/* Right label component, text,... */
rightLabel: PropTypes.any,
/** Sets the shape of the input field. It can be 'rounded', 'square' or 'circle' */
shape: PropTypes.oneOf(Object.values(INPUT_SHAPES)),
/* 'Sets the size of the inputAddon */
Expand Down
4 changes: 3 additions & 1 deletion components/atom/input/src/Input/Wrappers/Addons/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const BASE_CLASS_ADDON = `${BASE}--withAddon`
export const BASE_CLASS_ADDON_WRAPPER = `${BASE_CLASS_ADDON}Wrapper`
export const ADDON_TYPES = {
LEFT: 'left',
RIGHT: 'right'
RIGHT: 'right',
RIGHT_LABEL: 'rightLabel',
LEFT_LABEL: 'leftLabel'
}

export const getClassName = ({type}) =>
Expand Down
10 changes: 10 additions & 0 deletions components/atom/input/src/Input/Wrappers/Addons/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
border-width: $bdw-atom-input-addon-left;
}

&--rightLabel {
border-width: $bdw-atom-input-addon-right;
background: none;
}

&--leftLabel {
background: none;
border-width: $bdw-atom-input-addon-left;
}

&Wrapper {
display: flex;
@include atom-input-shape-wrapper(
Expand Down
22 changes: 18 additions & 4 deletions components/atom/input/src/Input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const BaseInput = forwardRef(
(
{
button,
children,
leftAddon,
rightAddon,
leftIcon,
rightIcon,
children,
leftLabel,
onClickLeftIcon,
onClickRightIcon,
rightAddon,
rightIcon,
rightLabel,
size = SIZES.MEDIUM,
...inputProps
},
Expand All @@ -31,14 +33,22 @@ const BaseInput = forwardRef(
rightAddon={rightAddon}
shape={inputProps.shape}
size={size}
rightLabel={rightLabel}
leftLabel={leftLabel}
>
<InputIcons
leftIcon={leftIcon}
rightIcon={rightIcon}
onClickLeftIcon={onClickLeftIcon}
onClickRightIcon={onClickRightIcon}
>
<Input ref={forwardedRef} {...inputProps} size={size}>
<Input
ref={forwardedRef}
{...inputProps}
rightLabel={rightLabel}
leftLabel={leftLabel}
size={size}
>
{children}
</Input>
</InputIcons>
Expand All @@ -57,10 +67,14 @@ BaseInput.propTypes = {
leftAddon: PropTypes.any,
/* Right addon component, text,... */
rightAddon: PropTypes.any,
/* Right label component, text,... */
rightLabel: PropTypes.string,
/* Left icon component */
leftIcon: PropTypes.node,
/* Left icon component */
rightIcon: PropTypes.node,
/* Left label component, text,... */
leftLabel: PropTypes.string,
/* Left icon click callback */
onClickLeftIcon: PropTypes.func,
/* Right icon click callback */
Expand Down
6 changes: 5 additions & 1 deletion components/atom/input/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const getClassNames = ({
size,
charsSize,
hideInput,
rightLabel,
leftLabel,
noBorder,
readOnly,
errorState,
Expand All @@ -65,6 +67,8 @@ export const getClassNames = ({
errorState && `${BASE_CLASS}--${INPUT_STATES.ERROR}`,
errorState === false && `${BASE_CLASS}--${INPUT_STATES.SUCCESS}`,
state && `${BASE_CLASS}--${state}`,
shape && `${BASE_CLASS}-shape-${shape}`
shape && `${BASE_CLASS}-shape-${shape}`,
rightLabel && `${BASE_CLASS}-right-label`,
leftLabel && `${BASE_CLASS}-left-label`
)
}