Skip to content

Commit

Permalink
feat: Replace a with ui5link (#2824)
Browse files Browse the repository at this point in the history
* replace a with ui5link

* adjust component

* fix focus

* improve comment msg

* changes after review

* use ts

* fix after review

* add disabled param

* remove unused link

* fix integration test
  • Loading branch information
dbadura authored Mar 19, 2024
1 parent 3bc527a commit c998f58
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 57 deletions.
10 changes: 2 additions & 8 deletions src/components/Extensibility/components-form/Modules/Modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useGetTranslation } from 'components/Extensibility/helpers';
import { useTranslation } from 'react-i18next';
import { fromJS } from 'immutable';

import { CheckBox, Icon, MessageStrip } from '@ui5/webcomponents-react';
import { CheckBox, MessageStrip } from '@ui5/webcomponents-react';
import { ResourceForm } from 'shared/ResourceForm';
import { Dropdown } from 'shared/ResourceForm/inputs';

Expand Down Expand Up @@ -207,14 +207,8 @@ export function Modules({ storeKeys, resource, onChange, schema, required }) {
/>

{link ? (
<ExternalLink url={link} style={spacing.sapUiMediumMarginTop}>
<ExternalLink url={link} iconStyle={spacing.sapUiMediumMarginTop}>
{t('extensibility.widgets.modules.documentation')}
<Icon
name="inspect"
design="Information"
className="ui5-icon-s"
style={spacing.sapUiTinyMarginBegin}
/>
</ExternalLink>
) : null}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export function TokenRequestModal({
<CopiableText
iconOnly
buttonText={t('common.buttons.copy')}
style={spacing.sapUiTinyMarginEnd}
textToCopy={kubeconfigYaml}
disabled={token === ''}
/>
Expand Down
5 changes: 3 additions & 2 deletions src/shared/components/CopiableText/CopiableText.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ CopiableText.propTypes = {
buttonText: PropTypes.string,
children: PropTypes.node,
iconOnly: PropTypes.bool,
disabled: PropTypes.bool,
};

export function CopiableText({
textToCopy,
buttonText,
children,
iconOnly,
...buttonProps
disabled,
}) {
const { t } = useTranslation();
return (
Expand All @@ -32,8 +33,8 @@ export function CopiableText({
iconEnd
design="Transparent"
style={spacing.sapUiTinyMarginBegin}
disabled={disabled}
onClick={() => copyToCliboard(textToCopy)}
{...buttonProps}
>
{buttonText ? buttonText : null}
</Button>
Expand Down
7 changes: 7 additions & 0 deletions src/shared/components/DescriptionHint/DescriptionHint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, Popover, Text } from '@ui5/webcomponents-react';
import { createPortal } from 'react-dom';
import { useRef } from 'react';

export function HintButton({
setShowTitleDescription,
Expand All @@ -8,10 +9,12 @@ export function HintButton({
style,
context,
}) {
const descBtnRef = useRef(null);
return (
<>
<Button
id={`descriptionOpener-${context}`}
ref={descBtnRef}
icon="hint"
design="Transparent"
style={style}
Expand All @@ -22,6 +25,10 @@ export function HintButton({
{createPortal(
<Popover
opener={`descriptionOpener-${context}`}
//Point initial focus to other component removes the focus from the link in description
onAfterOpen={() => {
descBtnRef.current.focus();
}}
open={showTitleDescription}
onAfterClose={() => setShowTitleDescription(false)}
placementType="Right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
align-items: center;
gap: 20px;
}

&__link {
font-size: var(--sapFontSize);
text-decoration: none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ export const EmptyListComponent = ({
{buttonText}
</Button>
)}
{url && (
<ExternalLink
className="emptyListComponent__link"
text="Learn More"
url={url}
/>
)}
{url && <ExternalLink text="Learn More" url={url} />}
</div>
{children}
</IllustratedMessage>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { CopiableText } from 'shared/components/CopiableText/CopiableText';
import { ExternalLink } from 'shared/components/ExternalLink/ExternalLink';
import { ReactNode } from 'react';

export const CopiableLink = props => {
export type LinkProps = {
url: string;
textToCopy?: string;
iconOnly?: boolean;
buttonText?: string;
children?: ReactNode;
};

export const CopiableLink = (props: LinkProps) => {
return (
<CopiableText textToCopy={props.url}>
<ExternalLink {...props} />
</CopiableText>
);
};

CopiableLink.propTypes = ExternalLink.propTypes;
24 changes: 8 additions & 16 deletions src/shared/components/ExternalLink/ExternalLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { Icon } from '@ui5/webcomponents-react';
import { Icon, Link } from '@ui5/webcomponents-react';

import { spacing } from '@ui5/webcomponents-react-base';

Expand All @@ -9,37 +9,29 @@ type LinkProps = {
text?: string;
className?: string;
children?: ReactNode;
dataTestId?: string;
style?: React.CSSProperties;
design?: 'Default' | 'Subtle' | 'Emphasized';
iconStyle?: React.CSSProperties;
};

export const ExternalLink = ({
url,
text,
className,
children,
dataTestId,
style,
design = 'Default',
iconStyle,
}: LinkProps) => {
const { t } = useTranslation();

return (
<a
className={`bsl-link ${className}`}
href={url}
target="_blank"
rel="noopener noreferrer"
data-test-id={dataTestId}
style={style}
>
<Link design={design} href={url} target="_blank">
{text || children || url}
<Icon
design="Information"
name="inspect"
className="bsl-icon-s"
style={spacing.sapUiTinyMarginBegin}
style={{ ...spacing.sapUiTinyMarginBegin, ...(iconStyle || {}) }}
aria-label={t('common.ariaLabel.new-tab-link')}
/>
</a>
</Link>
);
};
14 changes: 0 additions & 14 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ body {
cursor: pointer;
}

.bsl-link {
color: var(--sapLinkColor);
cursor: pointer;
text-decoration: none;

&:hover {
text-decoration: underline;
}

&.no-border {
border: none;
}
}

.panel-grid {
display: grid;
grid-template-columns: 2fr 2fr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ context('Test Pizzas', () => {

cy.contains('DELIVERY');
cy.contains('CASH');
cy.contains('a', 'extensibility docs');
cy.contains('ui5-link', 'extensibility docs');
cy.checkItemOnGenericListLink('margherita-order');

cy.clickGenericListLink('diavola-order');
Expand Down

0 comments on commit c998f58

Please sign in to comment.