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

[Maps] Improving design and a11y for attribution layer settings #38

Merged
merged 4 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import 'layer_panel';
@import 'layer_settings/attribution_popover';
@import 'layer_settings/index';
@import 'filter_editor/filter_editor';
@import 'join_editor/resources/join';
@import 'style_settings/style_settings';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.mapAttributionFormRow__legend {
margin-bottom: $euiSizeXS;
}

.mapAttributionFormRow__buttons {
display: flex;
justify-content: flex-end;
margin-top: $euiSizeXS;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.mapAttributionPopover {
width: $euiSizeXXL * 12;
width: $euiSizeXXL * 8;
Copy link
Owner

Choose a reason for hiding this comment

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

Can we keep the original size? URLs can get very long and having more horizontal space makes the text input more usable.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I'll try to add some styles to make it more similar to the columnCompressed form row. I'll also try to remove the horizontal line.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import 'attribution_form_row';
@import 'attribution_popover';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { EuiButtonEmpty, EuiFlexGrid, EuiFlexItem, EuiFormRow, EuiLink } from '@elastic/eui';
import { EuiButtonEmpty, EuiFlexItem, EuiTitle, EuiLink, EuiPanel } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { Attribution } from '../../../../common/descriptor_types';
Expand All @@ -21,57 +21,74 @@ interface Props {
export function AttributionFormRow(props: Props) {
function renderAttribution() {
const layerDescriptor = props.layer.getDescriptor();
return layerDescriptor.attribution === undefined ? (
<AttributionPopover
onChange={props.onChange}
popoverButtonIcon="plusInCircleFilled"
popoverButtonLabel={i18n.translate('xpack.maps.attribution.addBtnLabel', {
defaultMessage: 'Add',
})}
label={''}
url={''}
/>
) : (
<div>
<EuiLink color="text" href={layerDescriptor.attribution.url} target="_blank">
{layerDescriptor.attribution.label}
</EuiLink>
<EuiFlexGrid>
<EuiFlexItem grow={false}>
<AttributionPopover
onChange={props.onChange}
popoverButtonIcon="pencil"
popoverButtonLabel={i18n.translate('xpack.maps.attribution.editBtnLabel', {
defaultMessage: 'Edit',
})}
label={layerDescriptor.attribution.label}
url={layerDescriptor.attribution.url}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={() => {
props.onChange();
}}
size="xs"
iconType="trash"
>
<FormattedMessage id="xpack.maps.attribution.clearBtnLabel" defaultMessage="Clear" />
</EuiButtonEmpty>

return (
<fieldset aria-labelledby="mapsLayerSettingsAttributionLegend">
<EuiTitle size="xxxs">
<legend id="mapsLayerSettingsAttributionLegend" className="mapAttributionFormRow__legend">
{i18n.translate('xpack.maps.layerSettings.attributionLegend', {
defaultMessage: 'Attribution',
})}
</legend>
</EuiTitle>

{layerDescriptor.attribution === undefined ? (
<AttributionPopover
onChange={props.onChange}
popoverButtonIcon="plusInCircleFilled"
popoverButtonLabel={i18n.translate('xpack.maps.attribution.addBtnLabel', {
defaultMessage: 'Add attribution',
})}
popoverButtonAriaLabel={i18n.translate('xpack.maps.attribution.addBtnAriaLabel', {
defaultMessage: 'Add attribution',
})}
label={''}
url={''}
/>
) : (
<EuiFlexItem>
<EuiPanel color="subdued" paddingSize="s" className="mapAttributionFormRow__field">
<EuiLink color="text" href={layerDescriptor.attribution.url} target="_blank">
{layerDescriptor.attribution.label}
</EuiLink>
</EuiPanel>

<div className="mapAttributionFormRow__buttons">
<AttributionPopover
onChange={props.onChange}
popoverButtonIcon="pencil"
popoverButtonAriaLabel={i18n.translate('xpack.maps.attribution.addBtnAriaLabel', {
defaultMessage: 'Edit attribution',
})}
popoverButtonLabel={i18n.translate('xpack.maps.attribution.editBtnLabel', {
defaultMessage: 'Edit',
})}
label={layerDescriptor.attribution.label}
url={layerDescriptor.attribution.url}
/>

<EuiButtonEmpty
onClick={() => {
props.onChange();
}}
size="xs"
iconType="trash"
color="danger"
aria-label={i18n.translate('xpack.maps.attribution.clearBtnAriaLabel', {
defaultMessage: 'Clear attribution',
})}
>
<FormattedMessage
id="xpack.maps.attribution.clearBtnLabel"
defaultMessage="Clear"
/>
</EuiButtonEmpty>
</div>
</EuiFlexItem>
</EuiFlexGrid>
</div>
)}
</fieldset>
);
}

return props.layer.getSource().getAttributionProvider() ? null : (
<EuiFormRow
label={i18n.translate('xpack.maps.layerSettings.attributionLabel', {
defaultMessage: 'Attribution',
})}
display="columnCompressed"
>
{renderAttribution()}
</EuiFormRow>
);
return props.layer.getSource().getAttributionProvider() ? null : renderAttribution();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Attribution } from '../../../../common/descriptor_types';
interface Props {
onChange: (attribution: Attribution) => void;
popoverButtonLabel: string;
popoverButtonAriaLabel: string;
popoverButtonIcon: string;
label: string;
url: string;
Expand Down Expand Up @@ -73,9 +74,11 @@ export class AttributionPopover extends Component<Props, State> {
_renderPopoverButton() {
return (
<EuiButtonEmpty
aria-label={this.props.popoverButtonAriaLabel}
onClick={this._togglePopover}
size="xs"
iconType={this.props.popoverButtonIcon}
flush="left"
>
{this.props.popoverButtonLabel}
</EuiButtonEmpty>
Expand All @@ -99,15 +102,28 @@ export class AttributionPopover extends Component<Props, State> {
})}
fullWidth
>
<EuiFieldText fullWidth value={this.state.label} onChange={this._onLabelChange} />
<EuiFieldText
compressed
fullWidth
value={this.state.label}
onChange={this._onLabelChange}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('xpack.maps.attribution.urlLabel', {
defaultMessage: 'Link',
})}
fullWidth
>
<EuiFieldText fullWidth value={this.state.url} onChange={this._onUrlChange} />
<EuiFieldText
compressed
fullWidth
value={this.state.url}
onChange={this._onUrlChange}
placeholder={i18n.translate('xpack.maps.attribution.urlPlaceholder', {
defaultMessage: 'http://myurl.com',
})}
/>
</EuiFormRow>
<EuiSpacer size="xs" />
<EuiPopoverFooter>
Expand All @@ -130,6 +146,7 @@ export class AttributionPopover extends Component<Props, State> {
return (
<EuiPopover
id="attributionPopover"
panelPaddingSize="s"
anchorPosition="leftCenter"
button={this._renderPopoverButton()}
isOpen={this.state.isPopoverOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
EuiSpacer,
EuiSwitch,
EuiSwitchEvent,
EuiHorizontalRule,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -139,6 +140,7 @@ export function LayerSettings(props: Props) {
{renderZoomSliders()}
<AlphaSlider alpha={props.layer.getAlpha()} onChange={onAlphaChange} />
{renderShowLabelsOnTop()}
<EuiHorizontalRule margin="s" />
<AttributionFormRow layer={props.layer} onChange={onAttributionChange} />
</EuiPanel>

Expand Down