Skip to content

Commit

Permalink
feat(header): add documentation ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Mar 28, 2022
1 parent 7e3685d commit 01e8bfe
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
5 changes: 5 additions & 0 deletions assets/properties-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@
margin-top: -6px;
}

.bio-properties-panel-header-actions {
margin-left: auto;
margin-top: auto;
}

/**
* Scroll container
*/
Expand Down
24 changes: 21 additions & 3 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { ExternalLinkIcon } from './icons';

/**
* @typedef { { getElementLabel: Function, getTypeLabel: Function, getElementIcon: Function } } HeaderProvider
* @typedef { {
* getElementLabel: (element: djs.model.base) => string,
* getTypeLabel: (element: djs.model.base) => string,
* getElementIcon: (element: djs.model.base) => import('preact').Component,
* getDocumentationRef: (element: djs.model.base) => string
* } } HeaderProvider
*/

/**
Expand All @@ -15,13 +22,16 @@ export default function Header(props) {
} = props;

const {
getElementIcon,
getDocumentationRef,
getElementLabel,
getTypeLabel,
getElementIcon
} = headerProvider;

const label = getElementLabel(element);
const type = getTypeLabel(element);
const documentationRef = getDocumentationRef && getDocumentationRef(element);

const ElementIcon = getElementIcon(element);

return (<div class="bio-properties-panel-header">
Expand All @@ -30,10 +40,18 @@ export default function Header(props) {
</div>
<div class="bio-properties-panel-header-labels">
<div title={ type } class="bio-properties-panel-header-type">{ type }</div>
{ getElementLabel(element) ?
{ label ?
<div title={ label } class="bio-properties-panel-header-label">{ label }</div> :
null
}
</div>
<div class="bio-properties-panel-header-actions">
{ documentationRef ?
<a rel="noopener" class="bio-properties-panel-header-link" href={ documentationRef } target="_blank">
<ExternalLinkIcon />
</a> :
null
}
</div>
</div>);
}
1 change: 1 addition & 0 deletions src/components/icons/ExternalLink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/icons/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as ArrowIcon } from './Arrow.svg';
export { default as CreateIcon } from './Create.svg';
export { default as DeleteIcon } from './Delete.svg';
export { default as ExternalLinkIcon } from './ExternalLink.svg';
export { default as FeelRequiredIcon } from './FeelRequired.svg';
export { default as FeelOptionalIcon } from './FeelOptional.svg';
38 changes: 38 additions & 0 deletions test/spec/components/Header.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,44 @@ describe('<Header>', function() {
expect(iconNode).to.exist;
});

it('should NOT render documentation ref', function() {

// given
const provider = {
getElementLabel: () => 'name',
getTypeLabel: () => 'type',
getElementIcon: () => 'icon'
};

// when
const result = render(<Header headerProvider={ provider } />, { container });

const documentationNode = domQuery('.bio-properties-panel-header-link', result.container);

// then
expect(documentationNode).to.not.exist;
});


it('should render documentation ref', function() {

// given
const provider = {
getElementLabel: () => 'name',
getTypeLabel: () => 'type',
getElementIcon: () => 'icon',
getDocumentationRef: () => 'https://example.com'
};

// when
const result = render(<Header headerProvider={ provider } />, { container });

const documentationNode = domQuery('.bio-properties-panel-header-link', result.container);

// then
expect(documentationNode).to.exist;
});


describe('a11y', function() {

Expand Down

0 comments on commit 01e8bfe

Please sign in to comment.