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

[MI-2711]: Create Countdown component #61

Merged
merged 30 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eb245c6
[MI-2711]: Create Countdown component
SaurabhSharma-884 Feb 3, 2023
66282c1
[MI-2711]: Add onFinished handler function
SaurabhSharma-884 Feb 6, 2023
ac08fcd
[MI-2711]: Self review fix
SaurabhSharma-884 Feb 6, 2023
03310be
[MI-2712]: Create MultiProgress component
SaurabhSharma-884 Feb 6, 2023
5f035bb
[MI-2712]: self review fix
SaurabhSharma-884 Feb 6, 2023
cd064c7
Merge branch 'mm_v6' of s.github.com:Brightscout/mm-ui-library into M…
SaurabhSharma-884 Feb 7, 2023
d1aebce
Merge branch 'mm_v6' of s.github.com:Brightscout/mm-ui-library into M…
SaurabhSharma-884 Feb 7, 2023
116d2ef
Merge branch 'MI-2712' of s.github.com:Brightscout/mm-ui-library into…
SaurabhSharma-884 Feb 8, 2023
5900602
Merge branch 'MI-2623' of s.github.com:Brightscout/mm-ui-library into…
SaurabhSharma-884 Feb 8, 2023
35fcf70
[MI-2711]: fix Tab component
SaurabhSharma-884 Feb 17, 2023
05a3e59
MI-2752: Add MM auto suggestion search component
atisheyJain03 Feb 22, 2023
50a95b0
[MI-2752]: Fixes after self review
atisheyJain03 Mar 9, 2023
afe2baa
Merge branch 'MI-2711' of gitpro.ttaallkk.top-atishey:Brightscout/mm-ui-librar…
atisheyJain03 Mar 10, 2023
e3409f3
[MI-2752]: Review fixes
atisheyJain03 Mar 10, 2023
4e0113d
Merge pull request #64 from Brightscout/MI-2752
atisheyJain03 Mar 10, 2023
030a34f
[MI-2867]: Add search label auto-suggest hints and other style fixes
SaurabhSharma-884 Mar 14, 2023
81fd023
[MI-2867]: Revert List component changes
SaurabhSharma-884 Mar 15, 2023
274e358
[MI-2867]: Add review fix
SaurabhSharma-884 Mar 16, 2023
41d9555
Merge pull request #71 from Brightscout/MI-2867
SaurabhSharma-884 Mar 16, 2023
8d03e33
[MI-2711]: Update version
SaurabhSharma-884 Mar 17, 2023
74621e9
[MI-2925]: Open list on Input focus
SaurabhSharma-884 Mar 24, 2023
0b5c8a4
[MI-2925]: Fix prop documentation
SaurabhSharma-884 Mar 24, 2023
c3a692e
Merge pull request #74 from Brightscout/MI-2925
SaurabhSharma-884 Mar 24, 2023
d3a9162
[MI-2931]: Fix option list on open and update version
SaurabhSharma-884 Mar 25, 2023
528b290
Merge pull request #75 from Brightscout/MI-2931
SaurabhSharma-884 Mar 25, 2023
d0edc98
[MI-2711]: Fix lint errors
SaurabhSharma-884 Apr 3, 2023
9383869
[MI-2711]: Add review fixes
SaurabhSharma-884 Apr 4, 2023
8e11de1
Merge branch 'mm_v6' of s.github.com:Brightscout/mm-ui-library into M…
SaurabhSharma-884 Apr 4, 2023
a266960
[MI-2711]: Review fixes
SaurabhSharma-884 Apr 7, 2023
8a94df8
[MI-2711]: Review fix
SaurabhSharma-884 Apr 7, 2023
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/Countdown/Countdown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export interface CountdownProps {
* To be called when countdown is over
*/
onFinished?: () => void;
}
}
5 changes: 2 additions & 3 deletions src/components/Countdown/Countdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ const CountdownTemplate: Story<CountdownProps> = (args) => <Countdown {...args}/
// Default
export const Default = CountdownTemplate.bind({});
Default.args = {
endTime: 1676007000000, // 2023/02/10 11:00
endTime: Date.now() + 172800000, // Today + 2 Days
};

// Custom countdown
export const Custom = CountdownTemplate.bind({});
Custom.args = {
endTime: 1676007000000, // 2023/02/10 11:00
endTime: Date.now() + 172800000,
showDays: true,
showHours: true,
showMinutes: true,
};

68 changes: 30 additions & 38 deletions src/components/Countdown/Countdown.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,42 @@ import styled from 'styled-components';
import Colors from '@Styles/colorsForJs.module.scss';

// Styles from card wrapper
export const CountdownWrapper = styled.div(() => {
return {
display: 'flex',
flexDirection: 'column' as const,
alignItems: 'center',
justifyContent: 'center',
background: Colors.centerChannel_4,
borderRadius: '4px',
padding: 16,
minWidth: 'fit-content',
};
export const CountdownWrapper = styled.div({
display: 'flex',
flexDirection: 'column' as const,
alignItems: 'center',
justifyContent: 'center',
background: Colors.centerChannel_4,
borderRadius: '4px',
padding: 16,
minWidth: 'fit-content',
});

// Styles for timer
export const Timer = styled.h2(() => {
return {
fontWeight: 600,
fontSize: '22px',
lineHeight: '28px',
color: Colors.centerChannel,
letterSpacing: '0.09em',
marginBottom: '4px',
minWidth: 'max-content',
minHeight: '28px',
};
export const Timer = styled.h2({
fontWeight: 600,
fontSize: '22px',
lineHeight: '28px',
color: Colors.centerChannel,
letterSpacing: '1.4px',
marginBottom: '4px',
minWidth: 'max-content',
minHeight: '28px',
});

// Styles for time label
export const TimeLabel = styled.p(() => {
return {
fontWeight: 400,
fontSize: '12px',
lineHeight: '20px',
color: Colors.centerChannel_72,
minWidth: '22px',
margin: 0,
};
export const TimeLabel = styled.p({
fontWeight: 400,
fontSize: '12px',
lineHeight: '20px',
color: Colors.centerChannel_72,
minWidth: '22px',
margin: 0,
});

// Styles for time label wrapper
export const TimeLabelWrapper = styled.div(() => {
return {
display: 'flex',
alignItems: 'center',
gap: 30,
};
});
export const TimeLabelWrapper = styled.div({
display: 'flex',
alignItems: 'center',
gap: 30,
});
2 changes: 1 addition & 1 deletion src/components/Countdown/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {Countdown} from './Countdown.component';
export {Countdown} from './Countdown.component';
42 changes: 28 additions & 14 deletions src/components/Input/Input.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {extendClassname} from '@Utils';

import {InputErrorMessage} from 'commonStyledComponents/InputErrorMessage/InputErrorMessage.styles';

import colors from '@Styles/colorsForJs.module.scss';

import {InputProps} from './Input';
import {
StyledInput,
Expand Down Expand Up @@ -74,36 +76,48 @@ export const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
}
};

/**
* Handle focus event on input element
*/
const handleOnInputFocus = (event: React.ChangeEvent<HTMLInputElement>) => {
if (onInputFocus) {
onInputFocus();
}
togglePlaceholderValue(event, 'focus');
};

/**
* Handle blur event on input element
*/
const handleOnInputBlur = (event: React.ChangeEvent<HTMLInputElement>) => {
togglePlaceholderValue(event, 'blur');
};

return (
<div>
<StyledInputContainer
className={`mm-input ${className}`}
fullWidth={fullWidth}
>
{iconName && <Icon
name={iconName}
size={16}
/>}
{iconName && (
<Icon
name={iconName}
size={16}
/>
)}
<StyledInput
ref={ref}
placeholder={inputLabel}
onFocus={(event: React.ChangeEvent<HTMLInputElement>) => {
if (onInputFocus) {
onInputFocus();
}
togglePlaceholderValue(event, 'focus');
}}
onBlur={(event: React.ChangeEvent<HTMLInputElement>) =>
togglePlaceholderValue(event, 'blur')
}
onFocus={handleOnInputFocus}
onBlur={handleOnInputBlur}
{...restProps}
/>
{searchQuery && (
<StyledIconButton onClick={onClose}>
<Icon
name='Close'
size={14}
iconColor='#ffffff'
iconColor={colors.white}
/>
</StyledIconButton>
)}
Expand Down
95 changes: 50 additions & 45 deletions src/components/MMSearch/MMSearch.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {AutoCompleteWrapper} from '@Components/AutoComplete/AutoComplete.styles'

import {Constants} from '@Constants';

import {ListItemType} from '@Components/List/List';

import {MMSearchProps} from './MMSearch';

/**
Expand Down Expand Up @@ -64,7 +66,7 @@ export const MMSearch = (props: MMSearchProps) => {
} = props;

const [searchQuery, setSearchQuery] = useState<string>('');
const [open, setOpen] = useState<boolean>(openOptions);
const [isOpen, setIsOpen] = useState<boolean>(openOptions);
const [active, setActive] = useState<number>(0);

const inputRef = useRef<HTMLInputElement>(null);
Expand All @@ -78,7 +80,7 @@ export const MMSearch = (props: MMSearchProps) => {
const onDropDownCloseHandler = (e: MouseEvent) => {
e.stopPropagation();
SaurabhSharma-884 marked this conversation as resolved.
Show resolved Hide resolved
if (e.target instanceof HTMLElement && !inputRef.current?.contains(e.target) && e.target !== inputRef.current) {
setOpen(false);
setIsOpen(false);
}
};

Expand All @@ -99,23 +101,21 @@ export const MMSearch = (props: MMSearchProps) => {
* If 'isOpen' is true and 'value' is empty, then set the active index to 0 and scroll the list to (0,0)
*/
useEffect(() => {
if (open) {
if (isOpen) {
setActive(0);
if (typeof listRef.current?.scrollTo === 'function') {
listRef.current.scrollTo(0, 0);
}
listRef.current.scrollTo(0, 0);
SaurabhSharma-884 marked this conversation as resolved.
Show resolved Hide resolved
}
}, [open]);
}, [isOpen]);

/**
* The function is called when an event is detected on the keyboard,
* so you can browse through the list and select one.
*/
const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (event) => {
if (!filteredOptions.length || !open) {
if (!filteredOptions.length || !isOpen) {
return;
}
if (event.key === 'Enter') {
if (event.key === Constants.KeyboardEvent.ENTER) {
event.preventDefault();
const option = filteredOptions[active];

Expand All @@ -126,29 +126,57 @@ export const MMSearch = (props: MMSearchProps) => {
setActive(0);
return;
}
if (event.key === 'ArrowUp') {
if (event.key === Constants.KeyboardEvent.ARROW_UP) {
event.preventDefault();
if (active === 0) {
return;
}
setActive((prev) => prev - 1);
if (typeof listRef.current?.scrollBy === 'function') {
listRef.current.scrollBy(0, -Constants.ITEM_HEIGHT);
}

listRef.current.scrollBy(0, -Constants.ITEM_HEIGHT);
SaurabhSharma-884 marked this conversation as resolved.
Show resolved Hide resolved

if (inputRef.current) {
inputRef.current.focus();
}
return;
}
if (event.key === 'ArrowDown') {
if (event.key === Constants.KeyboardEvent.ARROW_DOWN) {
event.preventDefault();
if (active === filteredOptions.length - 1) {
return;
}
setActive((prev) => prev + 1);
if (typeof listRef.current.scrollBy === 'function') {
listRef.current.scrollBy(0, Constants.ITEM_HEIGHT);
}

listRef.current.scrollBy(0, Constants.ITEM_HEIGHT);
SaurabhSharma-884 marked this conversation as resolved.
Show resolved Hide resolved
}
};

const handleOnClose = () => {
if (onClearInput) {
onClearInput();
}
if (inputRef?.current) {
inputRef.current.focus();
}
setIsOpen(true);
setSearchValue('');
setSearchQuery('');
};

const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setIsOpen(true);
setSearchQuery(e.target.value);
setSearchValue(e.target.value);
};

const handleItemClick = (event: React.MouseEvent<HTMLLIElement>, option: ListItemType) => {
setActive(0);
if (onSelect) {
onSelect(event, option);
}
setIsOpen(true);
if (inputRef.current) {
inputRef.current.focus();
}
};
SaurabhSharma-884 marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -165,40 +193,17 @@ export const MMSearch = (props: MMSearchProps) => {
value={searchValue}
label={label}
iconName={leadingIcon}
onClose={() => {
if (onClearInput) {
onClearInput();
}
if (inputRef?.current) {
inputRef.current.focus();
}
setOpen(true);
setSearchValue('');
setSearchQuery('');
}}
onChange={(e) => {
setOpen(true);
setSearchQuery(e.target.value);
setSearchValue(e.target.value);
}}
onInputFocus={() => setOpen(true)}
onClose={handleOnClose}
onChange={handleOnChange}
onInputFocus={() => setIsOpen(true)}
{...restProps}
/>
{Boolean(filteredOptions.length) && (
<List
ref={listRef}
isOpen={open}
isOpen={isOpen}
listItems={filteredOptions}
handleItemClick={(event, option) => {
setActive(0);
if (onSelect) {
onSelect(event, option);
}
setOpen(true);
if (inputRef.current) {
inputRef.current.focus();
}
}}
handleItemClick={handleItemClick}
value={searchQuery}
loading={optionsLoading}
isAutocomplete={true}
Expand Down
1 change: 1 addition & 0 deletions src/components/MMSearch/MMSearch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface MMSearchProps {

/**
* Flag used to open options
* @default false
*/
openOptions?: boolean;

Expand Down
4 changes: 1 addition & 3 deletions src/components/MMSearch/MMSearch.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export default {
args: {
label: 'Search...',
searchValue: '',
setSearchValue: (val: string) => {
console.log(val);
},
setSearchValue: (val: string) => val,
items: [{label: 'koko 1', value: 'Value 1'}],
},
} as Meta;
Expand Down
4 changes: 2 additions & 2 deletions src/components/MultiProgress/MultiProgress.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ProgressBarProps {
export type ProgressBarProps = {

/**
* Value of the progress in percentage of linear progress bar component
Expand All @@ -11,7 +11,7 @@ export interface ProgressBarProps {
color: string;
}

export interface MultiProgressBarProps {
export type MultiProgressBarProps = {

/**
* Configuration array for the multiple progress bars
Expand Down
Loading