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

FEAT: Add support for opaqueLabel on floating labels #245

Merged
merged 2 commits into from
Sep 20, 2023
Merged
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
5 changes: 4 additions & 1 deletion src/common/floating-label-utils/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type FloatingLabelHookProps = {
className?: string;
placeholder?: string;
invalid?: boolean;
opaqueLabel?: boolean;
onMount?: () => void;
}

Expand Down Expand Up @@ -76,6 +77,7 @@ export function useFloatingLabel({
inputValue,
placeholder,
invalid,
opaqueLabel,
onMount = () => {}
} : FloatingLabelHookProps): FloatingLabelHookReturn {
const _internalInputRef = useRef(null)
Expand Down Expand Up @@ -123,7 +125,8 @@ export function useFloatingLabel({
})

const floatingLabelClassName = classNames(`floating-label`, {
'floating-label--large': inputSize === `large`
'floating-label--large': inputSize === `large`,
'floating-label--opaque': opaqueLabel
})

const FragmentContainer = useCallback(({ children }) => <>{children}</>, [])
Expand Down
1 change: 1 addition & 0 deletions src/ebay-textbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import "@ebay/skin/textbox.css";
| --------------- | -------- | -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fluid` | Boolean | No | No | Takes the full width of the container
| `multiline` | Boolean | No | No | Renders a multi-line textbox if true |
| `opaqueLabel` | Boolean | No | No | Only works with floating label. If set, then background is obscured of the floating label. Used with textarea to prevent label overlap |
| `invalid` | Boolean | No | No | Indicates a field-level error with red border if true |
| `type` | String | No | No | Default: `text`, can be `password` if needed |
| `value` | String | No | No | Indicates the value of the input element, required for a controlled component. |
Expand Down
44 changes: 44 additions & 0 deletions src/ebay-textbox/__tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,50 @@ exports[`Storyshots ebay-textbox Floating label with autofocus 1`] = `
</DocumentFragment>
`;

exports[`Storyshots ebay-textbox Floating label with multiline 1`] = `
<DocumentFragment>
<span
class="floating-label"
>
<label
class="floating-label__label"
>
Floating label
</label>
<span
class="textbox"
>
<textarea
class="textbox__control"
type="text"
/>
</span>
</span>
</DocumentFragment>
`;

exports[`Storyshots ebay-textbox Floating label with multiline and opaque label 1`] = `
<DocumentFragment>
<span
class="floating-label floating-label--opaque"
>
<label
class="floating-label__label"
>
Floating label
</label>
<span
class="textbox"
>
<textarea
class="textbox__control"
type="text"
/>
</span>
</span>
</DocumentFragment>
`;

exports[`Storyshots ebay-textbox Floating label with placeholder, controlled 1`] = `
<DocumentFragment>
<p>
Expand Down
15 changes: 15 additions & 0 deletions src/ebay-textbox/__tests__/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,18 @@ storiesOf('ebay-textbox', module)

return <><Component/></>
})
.add('Floating label with multiline', () => (
<EbayTextbox
onChange={action('textbox-changed')}
floatingLabel="Floating label"
multiline
/>
))
.add('Floating label with multiline and opaque label', () => (
<EbayTextbox
onChange={action('textbox-changed')}
floatingLabel="Floating label"
multiline
opaqueLabel
/>
))
3 changes: 3 additions & 0 deletions src/ebay-textbox/textbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type EbayTextboxProps = {
onButtonClick?: EbayKeyboardEventHandler<HTMLInputElement, TextboxEventProps> &
EbayMouseEventHandler<HTMLInputElement, TextboxEventProps>;
forwardedRef?: Ref<HTMLTextAreaElement | HTMLInputElement>;
opaqueLabel?: boolean;
} & Omit<TextInputProps, 'onFocus' | 'onBlur' | 'onChange' | 'onKeyPress' | 'onKeyUp' | 'onKeyDown' | 'onInvalid'>;

const EbayTextbox: FC<EbayTextboxProps> = ({
Expand All @@ -63,6 +64,7 @@ const EbayTextbox: FC<EbayTextboxProps> = ({
floatingLabel,
children,
placeholder,
opaqueLabel,
...rest
}) => {
const [value, setValue] = useState(defaultValue)
Expand All @@ -84,6 +86,7 @@ const EbayTextbox: FC<EbayTextboxProps> = ({
inputValue: controlledValue || inputValue,
placeholder,
invalid,
opaqueLabel,
onMount: onFloatingLabelInit
})

Expand Down
Loading