-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable passing of documentation link to form properties panel
Related to camunda/team-hto#630
- Loading branch information
Showing
4 changed files
with
125 additions
and
64 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
103 changes: 44 additions & 59 deletions
103
packages/form-js-editor/src/features/properties-panel/PropertiesPanelHeaderProvider.js
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,65 +1,50 @@ | ||
import { textToLabel } from './Util'; | ||
|
||
import { iconsByType } from '../../render/components/icons'; | ||
|
||
import { getPaletteIcon } from '../palette/components/Palette'; | ||
|
||
import { useService } from './hooks'; | ||
|
||
const headerlessTypes = ['spacer', 'separator', 'expression', 'html']; | ||
|
||
export const PropertiesPanelHeaderProvider = { | ||
getElementLabel: (field) => { | ||
const { type } = field; | ||
|
||
if (headerlessTypes.includes(type)) { | ||
return ''; | ||
} | ||
|
||
if (type === 'text') { | ||
return textToLabel(field.text); | ||
} | ||
|
||
if (type === 'image') { | ||
return field.alt; | ||
} | ||
|
||
if (type === 'default') { | ||
return field.id; | ||
} | ||
|
||
return field.label; | ||
}, | ||
|
||
getElementIcon: (field) => { | ||
const { type } = field; | ||
|
||
// @Note: We know that we are inside the properties panel context, | ||
// so we can savely use the hook here. | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const fieldDefinition = useService('formFields').get(type).config; | ||
|
||
const Icon = fieldDefinition.icon || iconsByType(type); | ||
|
||
if (Icon) { | ||
return () => <Icon width="36" height="36" viewBox="0 0 54 54" />; | ||
} else if (fieldDefinition.iconUrl) { | ||
return getPaletteIcon({ iconUrl: fieldDefinition.iconUrl, label: fieldDefinition.label }); | ||
} | ||
}, | ||
|
||
getTypeLabel: (field) => { | ||
const { type } = field; | ||
|
||
if (type === 'default') { | ||
return 'Form'; | ||
} | ||
|
||
// @Note: We know that we are inside the properties panel context, | ||
// so we can savely use the hook here. | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const fieldDefinition = useService('formFields').get(type).config; | ||
|
||
return fieldDefinition.label || type; | ||
}, | ||
}; | ||
export function getPropertiesPanelHeaderProvider(options = {}) { | ||
const { getDocumentationRef, formFields } = options; | ||
|
||
return { | ||
getElementLabel: (field) => { | ||
const { type } = field; | ||
if (headerlessTypes.includes(type)) { | ||
return ''; | ||
} | ||
if (type === 'text') { | ||
return textToLabel(field.text); | ||
} | ||
if (type === 'image') { | ||
return field.alt; | ||
} | ||
if (type === 'default') { | ||
return field.id; | ||
} | ||
return field.label; | ||
}, | ||
|
||
getElementIcon: (field) => { | ||
const { type } = field; | ||
const fieldDefinition = formFields.get(type).config; | ||
const Icon = fieldDefinition.icon || iconsByType(type); | ||
if (Icon) { | ||
return () => <Icon width="36" height="36" viewBox="0 0 54 54" />; | ||
} else if (fieldDefinition.iconUrl) { | ||
return getPaletteIcon({ iconUrl: fieldDefinition.iconUrl, label: fieldDefinition.label }); | ||
} | ||
}, | ||
|
||
getTypeLabel: (field) => { | ||
const { type } = field; | ||
if (type === 'default') { | ||
return 'Form'; | ||
} | ||
const fieldDefinition = formFields.get(type).config; | ||
return fieldDefinition.label || type; | ||
}, | ||
|
||
getDocumentationRef, | ||
}; | ||
} |
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