-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0d1f53
commit d1c9a71
Showing
7 changed files
with
85 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 38 additions & 33 deletions
71
polaris-react/src/components/Picker/components/Activator/Activator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,54 @@ | ||
import {SelectIcon} from '@shopify/polaris-icons'; | ||
import React from 'react'; | ||
import React, {forwardRef} from 'react'; | ||
|
||
import {BlockStack} from '../../../BlockStack'; | ||
import {Icon} from '../../../Icon'; | ||
import {Text} from '../../../Text'; | ||
import {UnstyledButton} from '../../../UnstyledButton'; | ||
import {classNames} from '../../../../utilities/css'; | ||
|
||
import styles from './Activator.module.css'; | ||
|
||
export interface ActivatorProps { | ||
disabled?: boolean; | ||
label?: string; | ||
placeholder?: string; | ||
disabled?: boolean; | ||
selected?: string; | ||
onClick?(): void; | ||
} | ||
|
||
export function Activator({ | ||
disabled, | ||
label, | ||
placeholder, | ||
onClick, | ||
}: ActivatorProps) { | ||
return ( | ||
<UnstyledButton | ||
className={classNames(styles.Activator, disabled && styles.disabled)} | ||
disabled={disabled} | ||
onClick={onClick} | ||
> | ||
<BlockStack as="span" gap="100"> | ||
{label && ( | ||
<Text as="span" variant="bodySm" alignment="start" tone="subdued"> | ||
{label} | ||
</Text> | ||
)} | ||
export const Activator = forwardRef<HTMLButtonElement, ActivatorProps>( | ||
({disabled, label, placeholder, selected, onClick}, ref) => { | ||
return ( | ||
<button | ||
ref={ref} | ||
disabled={disabled} | ||
onClick={onClick} | ||
className={classNames(styles.Activator, disabled && styles.disabled)} | ||
> | ||
<BlockStack as="span" gap="100"> | ||
{label && ( | ||
<Text as="span" variant="bodySm" alignment="start" tone="subdued"> | ||
{label} | ||
</Text> | ||
)} | ||
|
||
{placeholder && ( | ||
<Text as="span" variant="bodyMd" alignment="start"> | ||
{placeholder} | ||
</Text> | ||
)} | ||
</BlockStack> | ||
<span> | ||
<Icon tone="subdued" source={SelectIcon} /> | ||
</span> | ||
</UnstyledButton> | ||
); | ||
} | ||
{(selected !== '' || placeholder) && ( | ||
<Text | ||
as="span" | ||
variant="bodyMd" | ||
alignment="start" | ||
tone={selected ? undefined : 'subdued'} | ||
> | ||
{selected || placeholder} | ||
</Text> | ||
)} | ||
</BlockStack> | ||
<span> | ||
<Icon tone="subdued" source={SelectIcon} /> | ||
</span> | ||
</button> | ||
); | ||
}, | ||
); | ||
|
||
Activator.displayName = 'Activator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters