Skip to content
Closed
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
155 changes: 105 additions & 50 deletions packages/connectors/src/connector-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalItem as Item,
__experimentalText as Text,
ExternalLink,
FlexBlock,
Expand All @@ -13,6 +12,7 @@ import {
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { chevronDown } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -26,6 +26,8 @@ export interface ConnectorItemProps {
description: string;
actionArea?: ReactNode;
children?: ReactNode;
isExpanded?: boolean;
onToggle?: () => void;
}

export function ConnectorItem( {
Expand All @@ -35,27 +37,51 @@ export function ConnectorItem( {
description,
actionArea,
children,
isExpanded = false,
onToggle,
}: ConnectorItemProps ) {
const classes = [ 'connector-card', isExpanded && 'is-expanded', className ]
.filter( Boolean )
.join( ' ' );

return (
<Item className={ className }>
<VStack spacing={ 4 }>
<HStack alignment="center" spacing={ 4 }>
{ icon }
<FlexBlock>
<VStack spacing={ 0 }>
<Text weight={ 600 } size={ 15 }>
{ name }
</Text>
<Text variant="muted" size={ 12 }>
{ description }
</Text>
</VStack>
</FlexBlock>
{ actionArea }
</HStack>
{ children }
</VStack>
</Item>
<div className={ classes }>
<HStack
alignment="center"
spacing={ 4 }
className="connector-card__header"
>
{ icon }
<FlexBlock>
<VStack spacing={ 0 }>
<Text weight={ 600 } size={ 15 }>
{ name }
</Text>
<Text variant="muted" size={ 12 }>
{ description }
</Text>
</VStack>
</FlexBlock>
{ actionArea }
{ onToggle && (
<Button
className="connector-card__toggle"
onClick={ onToggle }
aria-expanded={ isExpanded }
label={
isExpanded
? __( 'Collapse settings' )
: __( 'Expand settings' )
}
icon={ chevronDown }
size="compact"
/>
) }
</HStack>
{ isExpanded && children && (
<div className="connector-card__body">{ children }</div>
) }
</div>
);
}

Expand Down Expand Up @@ -116,7 +142,7 @@ export function DefaultConnectorSettings( {
);
}
if ( saveError ) {
return <span style={ { color: '#cc1818' } }>{ saveError }</span>;
return <Text style={ { color: '#cc1818' } }>{ saveError }</Text>;
}
return helpLink;
};
Expand Down Expand Up @@ -151,38 +177,67 @@ export function DefaultConnectorSettings( {
: undefined
}
>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'API Key' ) }
value={ apiKey }
onChange={ ( value ) => {
if ( ! readOnly ) {
setSaveError( null );
setApiKey( value );
}
} }
placeholder="YOUR_API_KEY"
disabled={ readOnly || isSaving }
help={ getHelp() }
/>
{ readOnly ? (
<Button variant="link" isDestructive onClick={ onRemove }>
{ __( 'Remove and replace' ) }
</Button>
) : (
<HStack justify="flex-start">
<Button
<>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
variant="primary"
disabled={ ! apiKey || isSaving }
accessibleWhenDisabled
isBusy={ isSaving }
onClick={ handleSave }
>
{ __( 'Save' ) }
label={ __( 'API Key' ) }
value={ apiKey }
onChange={ () => {} }
placeholder="YOUR_API_KEY"
disabled
help={ getHelp() }
/>
<Button variant="link" isDestructive onClick={ onRemove }>
{ __( 'Remove and replace' ) }
</Button>
</HStack>
</>
) : (
<>
<HStack
alignment="bottom"
spacing={ 3 }
className="connector-settings__inline"
>
<FlexBlock>
<TextControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'API Key' ) }
value={ apiKey }
onChange={ ( value ) => {
setSaveError( null );
setApiKey( value );
} }
placeholder="YOUR_API_KEY"
disabled={ isSaving }
/>
</FlexBlock>
<Button
__next40pxDefaultSize
variant="primary"
disabled={ ! apiKey || isSaving }
accessibleWhenDisabled
isBusy={ isSaving }
onClick={ handleSave }
>
{ __( 'Save' ) }
</Button>
</HStack>
{ ( saveError || helpLink ) && (
<Text
className="connector-settings__help"
variant={ saveError ? undefined : 'muted' }
size={ 12 }
style={
saveError ? { color: '#cc1818' } : undefined
}
>
{ saveError || helpLink }
</Text>
) }
</>
) }
</VStack>
);
Expand Down
33 changes: 18 additions & 15 deletions routes/connectors-home/default-connectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,30 @@ function ProviderConnector( {
icon={ <Logo /> }
name={ label }
description={ description }
isExpanded={ isExpanded }
onToggle={
pluginStatus === 'active'
? () => setIsExpanded( ! isExpanded )
: undefined
}
actionArea={
<HStack spacing={ 3 } expanded={ false }>
{ isConnected && <ConnectedBadge /> }
<Button
variant={
isExpanded || isConnected ? 'tertiary' : 'secondary'
}
size={
isExpanded || isConnected ? undefined : 'compact'
}
onClick={ handleButtonClick }
disabled={ pluginStatus === 'checking' || isBusy }
isBusy={ isBusy }
aria-expanded={ isExpanded }
>
{ getButtonLabel() }
</Button>
{ getButtonLabel() && (
<Button
variant={ isConnected ? 'tertiary' : 'secondary' }
size={ isConnected ? undefined : 'compact' }
onClick={ handleButtonClick }
disabled={ pluginStatus === 'checking' || isBusy }
isBusy={ isBusy }
>
{ getButtonLabel() }
</Button>
) }
</HStack>
}
>
{ isExpanded && pluginStatus === 'active' && (
{ pluginStatus === 'active' && (
<DefaultConnectorSettings
key={ isConnected ? 'connected' : 'setup' }
initialValue={ currentApiKey }
Expand Down
44 changes: 43 additions & 1 deletion routes/connectors-home/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,60 @@
margin: 0 auto;
padding: 24px;

.components-item {
.connector-card {
padding: 20px;
border-radius: 8px;
border: 1px solid #ddd;
background: #fff;
overflow: hidden;
}
Comment on lines +9 to 15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use Card from @wordpress/components?


.connector-card__header {
cursor: default;
}

.connector-card__toggle {
flex-shrink: 0;

svg {
transition: transform 0.2s ease;
}
}

.connector-card.is-expanded .connector-card__toggle svg {
transform: rotate(180deg);
}

.connector-card__body {
margin-top: 16px;
padding-top: 16px;
border-top: 1px solid #ddd;
}

.connector-settings .components-text-control__input {
font-family: monospace;
}

.connector-settings__inline {
// Align the Save button with the input field, not the label.
.components-flex-block {
min-width: 0;
}

> .components-button {
flex-shrink: 0;
}
}

.connector-settings__help {
font-size: 12px;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a scss var for this.

color: $gray-700;

a {
font-size: inherit;
}
}

> p {
text-align: center;
color: $gray-600;
Expand Down
10 changes: 1 addition & 9 deletions routes/connectors-home/use-connector-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ export function useConnectorPlugin( {
installPlugin();
} else if ( pluginStatus === 'inactive' ) {
activatePlugin();
} else {
setIsExpanded( ! isExpanded );
}
};

Expand All @@ -135,12 +133,6 @@ export function useConnectorPlugin( {
? __( 'Installing…' )
: __( 'Activating…' );
}
if ( isExpanded ) {
return __( 'Cancel' );
}
if ( isConnected ) {
return __( 'Edit' );
}
switch ( pluginStatus ) {
case 'checking':
return __( 'Checking…' );
Expand All @@ -149,7 +141,7 @@ export function useConnectorPlugin( {
case 'inactive':
return __( 'Activate' );
case 'active':
return __( 'Set up' );
return '';
}
};

Expand Down
Loading