Skip to content

Commit

Permalink
feat(dropdown): add icon variations property in dropdown component
Browse files Browse the repository at this point in the history
  • Loading branch information
anuradha9712 committed Sep 16, 2023
1 parent a89af39 commit bfcae4b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions core/components/atoms/dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ interface SyncProps {
* selected?: boolean;
* disabled?: boolean;
* group?: string;
* iconVariations?: {
* fill?: number;
* weight?: number; Range: [100, 700]
* grade?: number; Range: [-25, 200]
* opticalSize?: number; Range: [20px, 48px]
* }
* }
* </pre>
*
Expand All @@ -80,6 +86,7 @@ interface SyncProps {
* | selected | Denotes default selection of option <br/>(works in case of uncontrolled component) | |
* | disabled | Disables the option, making it unable to be pressed | |
* | group | Defines group to which the option belongs | |
* | iconVariations | Set font-variation-settings CSS property for Icons | |
*/
options: OptionSchema[];
/**
Expand Down
24 changes: 22 additions & 2 deletions core/components/atoms/dropdown/DropdownButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';
import { Icon, Text } from '@/index';
import { FontVariationType } from '@/common.type';

export type DropDownButtonSize = 'tiny' | 'regular';

Expand All @@ -14,6 +15,19 @@ export interface TriggerProps {
* Material icon name
*/
icon?: string;
/**
* Set font-variation-settings CSS property for Icons
*
* <pre className="DocPage-codeBlock">
* FontVariationType: {
* fill?: number;
* weight?: number; Range: [100, 700]
* grade?: number; Range: [-25, 200]
* opticalSize?: number; Range: [20px, 48px]
* }
* </pre>
*/
iconVariations?: FontVariationType;
/**
* String to show inside `Dropdown trigger` when no options are selected
* @default "Select"
Expand Down Expand Up @@ -54,6 +68,7 @@ const DropdownButton = React.forwardRef<HTMLButtonElement, DropdownButtonProps>(
open,
inlineLabel,
error,
iconVariations,
...rest
} = props;

Expand Down Expand Up @@ -98,12 +113,17 @@ const DropdownButton = React.forwardRef<HTMLButtonElement, DropdownButtonProps>(
</Text>
)}
{icon && !inlineLabel && (
<Icon appearance={buttonDisabled} className="d-flex align-items-center mr-4" name={icon} />
<Icon
appearance={buttonDisabled}
className="d-flex align-items-center mr-4"
name={icon}
variations={iconVariations}
/>
)}
{value && <span className={textClass}>{value}</span>}
</div>
)}
<Icon appearance={buttonDisabled} name={iconName} />
<Icon appearance={buttonDisabled} name={iconName} variations={iconVariations} />
</button>
);
});
Expand Down
12 changes: 11 additions & 1 deletion core/components/atoms/dropdown/DropdownList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,16 @@ const DropdownList = (props: OptionsProps) => {
if (firstEnabledOption !== cursor) setCursor(firstEnabledOption);
}, [firstEnabledOption]);

const { triggerSize = 'regular', placeholder = 'Select', icon, error, disabled, inlineLabel, triggerLabel } = props;
const {
triggerSize = 'regular',
placeholder = 'Select',
icon,
error,
disabled,
inlineLabel,
triggerLabel,
iconVariations,
} = props;

const CustomTrigger = customTrigger ? customTrigger(triggerLabel ? triggerLabel : placeholder) : <></>;
const NewCustomTrigger = React.cloneElement(CustomTrigger, { tabIndex: 0, ref: dropdownTriggerRef });
Expand All @@ -296,6 +305,7 @@ const DropdownList = (props: OptionsProps) => {
menu={menu}
error={error}
ref={dropdownTriggerRef}
iconVariations={iconVariations}
>
{triggerLabel}
</DropdownButton>
Expand Down
6 changes: 4 additions & 2 deletions core/components/atoms/dropdown/option/IconOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classNames from 'classnames';
const IconOption = (props: OptionTypeProps) => {
const { className, textClassName, onClickHandler, optionData, onUpdateActiveOption, color, dataTest } = props;

const { label, icon, disabled } = optionData;
const { label, icon, disabled, iconVariations } = optionData;

const OptionClass = classNames({
[`${className}`]: true,
Expand All @@ -24,7 +24,9 @@ const IconOption = (props: OptionTypeProps) => {
data-disabled={disabled}
>
{/* eslint-enable */}
{icon && <Icon className="Option-icon mr-4" data-test={`${dataTest}--Icon`} name={icon} />}
{icon && (
<Icon className="Option-icon mr-4" data-test={`${dataTest}--Icon`} name={icon} variations={iconVariations} />
)}
<div className={'Option-label'}>
<Text className={textClassName} color={color}>
{label}
Expand Down
3 changes: 2 additions & 1 deletion core/components/atoms/dropdown/option/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import IconWithMetaOption from './IconWithMetaOption';
import { MetaList, Text } from '@/index';
import { MetaListProps, IconProps, TextProps } from '@/index.type';
import { OptionType } from '../DropdownList';
import { ChangeEvent } from '@/common.type';
import { ChangeEvent, FontVariationType } from '@/common.type';

export type ClickEvent = React.MouseEvent<HTMLDivElement>;

Expand Down Expand Up @@ -42,6 +42,7 @@ export interface OptionSchema extends Record<string, any> {
selected?: boolean;
disabled?: boolean;
group?: string;
iconVariations?: FontVariationType;
}

export interface OptionTypeProps {
Expand Down

0 comments on commit bfcae4b

Please sign in to comment.