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

Add search message in search box #475

Open
wants to merge 4 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
8 changes: 7 additions & 1 deletion packages/pebble-web/src/components/OptionGroupCheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ export default class OptionGroupCheckBox<
clearVisible: this.clearVisible,
...this.props.advancedOptionsProps
};

const isSearchMessagePresent = !!rest.searchBoxProps?.message;
const _optionGroupCheckboxWrap = isSearchMessagePresent
? styles.optionGroupCheckBoxWrapWithMessage
: styles.optionGroupCheckBoxWrap;

return (
<div className={cx(styles.optionGroupCheckBoxWrap, wrapClassName)}>
<div className={cx(_optionGroupCheckboxWrap, wrapClassName)}>
<OptionGroup<OptionType>
{...rest}
advancedOptionsProps={advancedOptionsProps}
Expand Down
77 changes: 43 additions & 34 deletions packages/pebble-web/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { SearchProps } from "./typings/Search";
import {
searchStyle,
searchWrapperStyle,
clearContainer
clearContainer,
searchMessageColor
} from "./styles/Search.styles";
import Loader from "./Loader";
import { colors } from "pebble-shared";
import { messageStyle } from "./styles/Input.styles";

class Search extends React.PureComponent<SearchProps> {
searchInputRef: React.RefObject<HTMLInputElement> = React.createRef();
Expand All @@ -27,48 +29,55 @@ class Search extends React.PureComponent<SearchProps> {
className,
clearable,
value,
loading
loading,
message,
wrapperClassName
} = this.props;

const wrapperClassName = cx(searchWrapperStyle, {
const _searchBoxWrapperClassName = cx(searchWrapperStyle, {
__pebble__search__small: type === "small",
__pebble__search__large: type === "large",
__pebble__search__table: type === "table"
});

return (
<div className={cx(wrapperClassName, className)}>
{type !== "large" && showSearchIcon && <i className="pi pi-search" />}
<input
className={searchStyle}
type="text"
aria-label={placeholder}
placeholder={placeholder}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
onChange(e.target.value);
}}
ref={this.searchInputRef}
value={value}
{...inputProps}
/>
{loading && <Loader scale={0.4} color={colors.violet.base} />}
{clearable && (
<div
className={cx(clearContainer, {
__display: !!value && !!value.length
})}
onClick={() => {
if (this.searchInputRef.current) {
this.searchInputRef.current.value = "";
}
onChange("");
<div className={wrapperClassName}>
<div className={cx(_searchBoxWrapperClassName, className)}>
{type !== "large" && showSearchIcon && <i className="pi pi-search" />}
<input
className={searchStyle}
type="text"
aria-label={placeholder}
placeholder={placeholder}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
onChange(e.target.value);
}}
>
<i
className="pi pi-close"
style={{ display: "table-cell", verticalAlign: "middle" }}
/>
</div>
ref={this.searchInputRef}
value={value}
{...inputProps}
/>
{loading && <Loader scale={0.4} color={colors.violet.base} />}
{clearable && (
<div
className={cx(clearContainer, {
__display: !!value && !!value.length
})}
onClick={() => {
if (this.searchInputRef.current) {
this.searchInputRef.current.value = "";
}
onChange("");
}}
>
<i
className="pi pi-close"
style={{ display: "table-cell", verticalAlign: "middle" }}
/>
</div>
)}
</div>
{message && (
<div className={cx(messageStyle, searchMessageColor)}>{message}</div>
)}
</div>
);
Expand Down
10 changes: 8 additions & 2 deletions packages/pebble-web/src/components/shared/OptionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import Search from "../Search";
import {
searchBoxScrolledStyle,
searchBoxWrapper,
searchBoxHeight,
optionsWrapper,
searchBoxHeight
searchBoxHeightWithMessage
} from "../styles/OptionGroup.styles";
import { rowWrapper, advancedActionsWrapper } from "../styles/Options.styles";

Expand Down Expand Up @@ -124,6 +125,7 @@ class OptionGroup<OptionType> extends React.PureComponent<
searchBoxProps
} = this.props;
const { isScrolled, highlighted } = this.state;
const isMessagePresent = !!searchBoxProps?.message;

const _children = React.Children.map(children, (_option, i) => {
// `_option as React.ReactElement<OptionProps>` is a hack
Expand Down Expand Up @@ -175,7 +177,11 @@ class OptionGroup<OptionType> extends React.PureComponent<
<div
ref={this.optionRef}
style={{
paddingTop: searchBox ? searchBoxHeight : undefined
paddingTop: searchBox
? isMessagePresent
? searchBoxHeightWithMessage
: searchBoxHeight
: undefined
}}
className={cx(optionsWrapper, className)}
role={multiSelect ? "group" : "radiogroup"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { colors } from "pebble-shared";

export const optionWrapperMaxHeight = 316;
export const searchBoxHeight = 80;
export const searchBoxMessageHeight = 20;
export const searchBoxHeightWithMessage =
searchBoxHeight + searchBoxMessageHeight;

export const initialPadding = 20;
export const onScrollPadding = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@ import {
optionWrapperMaxHeight,
searchBoxHeight,
initialPadding,
onScrollPadding
onScrollPadding,
searchBoxHeightWithMessage
} from "./OptionGroup.styles";
import { smallButtonHeight } from "./Button.styles";
import { colors } from "pebble-shared";
export const optionGroupCheckBoxButtonWrapPadding = 20;
export const optionGroupCheckBoxButtonWrapPaddingTop = 10;

export const optionGroupCheckBoxWrapperHeight =
optionWrapperMaxHeight +
2 * (initialPadding - onScrollPadding) +
optionGroupCheckBoxButtonWrapPadding +
optionGroupCheckBoxButtonWrapPaddingTop +
smallButtonHeight;

export const optionGroupCheckBoxWrap = css({
maxHeight:
optionWrapperMaxHeight +
searchBoxHeight +
2 * (initialPadding - onScrollPadding) +
optionGroupCheckBoxButtonWrapPadding +
optionGroupCheckBoxButtonWrapPaddingTop +
smallButtonHeight,
maxHeight: optionGroupCheckBoxWrapperHeight + searchBoxHeight,
position: "relative"
});

export const optionGroupCheckBoxWrapWithMessage = css({
maxHeight: optionGroupCheckBoxWrapperHeight + searchBoxHeightWithMessage
});

export const optionGroupCheckBoxButtonWrap = css({
...mixins.flexSpaceBetween,
gap: 60,
Expand Down
4 changes: 4 additions & 0 deletions packages/pebble-web/src/components/styles/Search.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ export const clearContainer = css({
pointerEvents: "unset"
}
});

export const searchMessageColor = css({
color: colors.gray.base
});
2 changes: 2 additions & 0 deletions packages/pebble-web/src/components/typings/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export interface SearchProps {
clearable?: boolean;
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
loading?: boolean;
message?: string;
wrapperClassName?: string;
}
1 change: 1 addition & 0 deletions packages/pebble-web/stories/search.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ storiesOf("Components/Search", module).add(
clearable={boolean("showClearButton", true)}
value={store.state.query}
loading={boolean("showLoading", false)}
message={text("message", "Search Message ")}
/>
))
);