-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: add tooltip element to the builder #246
Open
jz5426
wants to merge
24
commits into
IBM:main
Choose a base branch
from
jz5426:dev.tooltip
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+327
−0
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2177c16
works
2dc4c47
lint fix
d56c4fe
svg
7f0e015
svg
046371d
feedback 1
fa0cf09
direction
fe6a38e
Merge branch 'main' of https://github.com/IBM/carbon-ui-builder into …
jz5426 d46ceda
prototype
jz5426 a01d195
Merge branch 'main' of https://github.com/IBM/carbon-ui-builder into …
jz5426 859be30
Merge branch 'main' of https://github.com/IBM/carbon-ui-builder into …
jz5426 9121343
progress
jz5426 9a87233
lint
jz5426 2cf2cae
fix gub
jz5426 c64a0ed
handle undefined attributes
jz5426 d0de671
lint
jz5426 9f0c5c6
not clickable in the canvas
jz5426 f636086
merge and fix export code
216300b
fix export code
55929d3
Merge branch 'main' of https://github.com/IBM/carbon-ui-builder into …
4b96ddf
Merge branch 'main' of https://github.com/IBM/carbon-ui-builder into …
58056f7
export fixes
50461a1
Update sdk/react/src/lib/fragment-components/a-definition-tooltip.tsx
jz5426 7544e3a
revision
2462361
optional alignemtn
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react'; | ||
import { DefinitionTooltip } from '@carbon/react'; | ||
import { CssClasses, SendSignal } from '../types'; | ||
import { stringToCssClassName } from '../utils'; | ||
import { commonSlots, slotsDisabled } from '../common-slots'; | ||
|
||
export interface DefinitionTooltipState { | ||
id: string; | ||
type: string; | ||
alignment?: string; | ||
codeContext: { | ||
name: string; | ||
}; | ||
description: string; | ||
isDefaultOpened?: boolean; | ||
definition?: string; | ||
isOpenOnHover?: boolean; | ||
cssClasses?: CssClasses[]; | ||
style?: any; | ||
} | ||
|
||
export const type = 'definition-tooltip'; | ||
export const slots = { | ||
...commonSlots, | ||
...slotsDisabled, | ||
enableOpenOnHover: (state: any) => ({ | ||
...state, | ||
isOpenOnHover: true | ||
}), | ||
disableOpenOnHover: (state: any) => ({ | ||
...state, | ||
isOpenOnHover: false | ||
}), | ||
toggleOpenOnHover: (state: any) => ({ | ||
...state, | ||
isOpenOnHover: !state.isOpenOnHover | ||
}), | ||
enableOpenOnDefault: (state: any) => ({ | ||
...state, | ||
isDefaultOpened: true | ||
}), | ||
disableOpenOnDefault: (state: any) => ({ | ||
...state, | ||
isDefaultOpened: false | ||
}), | ||
toggleOpenOnDefault: (state: any) => ({ | ||
...state, | ||
isDefaultOpened: !state.isDefaultOpened | ||
}), | ||
isOpenOnHover: 'boolean', | ||
isDefaultOpened: 'boolean', | ||
alignment: 'string', | ||
definition: 'string', | ||
description: 'string' | ||
}; | ||
|
||
export const signals = ['click']; | ||
|
||
export const UIDefinitionTooltip = ({ state, sendSignal }: { | ||
state: DefinitionTooltipState; | ||
setState: (state: any) => void; | ||
setGlobalState: (state: any) => void; | ||
sendSignal: SendSignal; | ||
}) => { | ||
if (state.type !== 'definition-tooltip') { | ||
// eslint-disable-next-line react/jsx-no-useless-fragment | ||
return <></>; | ||
} | ||
|
||
let cssClasses = state.cssClasses?.map((cc: any) => cc.id).join(' ') || ''; | ||
|
||
if (state.style) { | ||
if (cssClasses.length > 0) { | ||
cssClasses += ' '; | ||
} | ||
cssClasses += stringToCssClassName(state.codeContext.name); | ||
} | ||
|
||
return <DefinitionTooltip | ||
id={state.id} | ||
onClick={() => sendSignal(state.id, 'click')} | ||
align={state.alignment ? state.alignment : 'bottom-left'} | ||
definition={state.definition} | ||
name={state.codeContext?.name} | ||
openOnHover={state.isOpenOnHover} | ||
defaultOpen={state.isDefaultOpened} | ||
className={cssClasses}> | ||
{state.description} | ||
</DefinitionTooltip>; | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
214 changes: 214 additions & 0 deletions
214
sdk/react/src/lib/fragment-components/a-definition-tooltip.tsx
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 |
---|---|---|
@@ -0,0 +1,214 @@ | ||
import React from 'react'; | ||
import { | ||
Dropdown, | ||
DefinitionTooltip, | ||
TextInput, | ||
Checkbox | ||
} from '@carbon/react'; | ||
import { css } from 'emotion'; | ||
import { AComponent, ComponentInfo } from './a-component'; | ||
|
||
import image from './../assets/component-icons/tooltip.svg'; | ||
import { | ||
nameStringToVariableString, | ||
reactClassNamesFromComponentObj | ||
} from '../helpers/tools'; | ||
import { styleObjectToString } from '@carbon-builder/player-react'; | ||
|
||
const preventCheckEvent = css` | ||
pointer-events: none; | ||
`; | ||
|
||
export const ADefinitionTooltipSettingsUI = ({ selectedComponent, setComponent }: any) => { | ||
const alignments = [ | ||
{ id: 'top', text: 'Top' }, | ||
{ id: 'top-left', text: 'Top left' }, | ||
{ id: 'top-right', text: 'Top right' }, | ||
{ id: 'bottom', text: 'Bottom' }, | ||
{ id: 'bottom-left', text: 'Bottom left' }, | ||
{ id: 'bottom-right', text: 'Bottom right' }, | ||
{ id: 'left', text: 'Left' }, | ||
{ id: 'left-bottom', text: 'Left bottom' }, | ||
{ id: 'left-top', text: 'Left top' }, | ||
{ id: 'right', text: 'Right' }, | ||
{ id: 'right-bottom', text: 'Right bottom' }, | ||
{ id: 'right-top', text: 'Right top' } | ||
]; | ||
|
||
return <> | ||
<Dropdown | ||
id='alignment' | ||
label='Alignment of text' | ||
titleText='Alignment' | ||
items={alignments} | ||
selectedItem={alignments.find(item => item.id === selectedComponent.alignment)} | ||
itemToString={(item: any) => (item ? item.text : '')} | ||
onChange={(event: any) => setComponent({ | ||
...selectedComponent, | ||
alignment: event.selectedItem.id | ||
})} /> | ||
<TextInput | ||
id='description' | ||
value={selectedComponent.description} | ||
labelText='Description' | ||
onChange={(event: any) => setComponent({ | ||
...selectedComponent, | ||
description: event.currentTarget.value | ||
})} /> | ||
<TextInput | ||
id='definition' | ||
value={selectedComponent.definition} | ||
labelText='Tooltip Message' | ||
onChange={(event: any) => setComponent({ | ||
...selectedComponent, | ||
definition: event.currentTarget.value | ||
})} /> | ||
<Checkbox | ||
id='defaultOpen' | ||
labelText='Default open' | ||
checked={selectedComponent.isDefaultOpened} | ||
onChange={(_: any, { checked }: any) => setComponent({ | ||
...selectedComponent, | ||
isDefaultOpened: checked | ||
})} /> | ||
<Checkbox | ||
id='openOnHover' | ||
labelText='Open on hover' | ||
checked={selectedComponent.isOpenOnHover} | ||
onChange={(_: any, { checked }: any) => setComponent({ | ||
...selectedComponent, | ||
isOpenOnHover: checked | ||
})} /> | ||
</>; | ||
}; | ||
|
||
export const ADefinitionTooltipCodeUI = ({ selectedComponent, setComponent }: any) => <TextInput | ||
value={selectedComponent.codeContext?.name} | ||
id='input-name' | ||
labelText='Input name' | ||
onChange={(event: any) => { | ||
setComponent({ | ||
...selectedComponent, | ||
codeContext: { | ||
...selectedComponent.codeContext, | ||
name: event.currentTarget.value | ||
} | ||
}); | ||
}} />; | ||
|
||
export const ADefinitionTooltip = ({ | ||
componentObj, | ||
...rest | ||
}: any) => { | ||
return ( | ||
<AComponent | ||
componentObj={componentObj} | ||
rejectDrop={true} | ||
{...rest}> | ||
<div className={`${preventCheckEvent} ${componentObj.cssClasses?.map((cc: any) => cc.id).join(' ')} `}> | ||
<DefinitionTooltip | ||
className={css`${styleObjectToString(componentObj.style)}`} | ||
definition={componentObj.definition} | ||
align={componentObj.alignment}> | ||
{componentObj.description} | ||
</DefinitionTooltip> | ||
</div> | ||
</AComponent> | ||
); | ||
}; | ||
|
||
export const componentInfo: ComponentInfo = { | ||
component: ADefinitionTooltip, | ||
settingsUI: ADefinitionTooltipSettingsUI, | ||
codeUI: ADefinitionTooltipCodeUI, | ||
keywords: ['definition tooltip', 'definition', 'tooltip'], | ||
name: 'Definition tooltip', | ||
type: 'definition-tooltip', | ||
defaultComponentObj: { | ||
type: 'definition-tooltip', | ||
description: 'sample text' | ||
}, | ||
image, | ||
codeExport: { | ||
angular: { | ||
latest: { | ||
inputs: ({ json }) => ` | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}Description = "${json.description ? json.description : 'description'}"; | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}IsOpen = ${json.isDefaultOpened ? json.isDefaultOpened : false}; | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}Align: any = "${json.alignment ? json.alignment : 'bottom-start' }"; | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}Definition = "${json.definition ? | ||
json.definition : 'default tooltip message' }";`, | ||
outputs: ({ json }) => { | ||
const name = nameStringToVariableString(json.codeContext?.name); | ||
return `@Output() ${name}IsOpenChange = new EventEmitter<any>(); | ||
@Output() ${name}OnClose = new EventEmitter<any>(); | ||
@Output() ${name}OnOpen = new EventEmitter<any>();`; | ||
}, | ||
imports: ['TooltipModule'], | ||
code: ({ json }) => { | ||
const name = nameStringToVariableString(json.codeContext?.name); | ||
return `<cds-tooltip-definition | ||
[isOpen]="${name}IsOpen" | ||
[align]="${name}Align" | ||
(onOpen)="${name}OnOpen.emit($event)" | ||
(onClose)="${name}OnClose.emit($event)" | ||
(isOpenChange)="${name}IsOpenChange.emit($event)" | ||
[description]="${name}Definition"> | ||
{{${name}Description}} | ||
</cds-tooltip-definition>`; | ||
} | ||
}, | ||
v10: { | ||
inputs: ({ json }) => ` | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}Description = "${json.description ? json.description : 'description'}"; | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}IsOpen = ${json.isDefaultOpened ? json.isDefaultOpened : false}; | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}Align: any = "${json.alignment ? json.alignment : 'bottom-left' }"; | ||
@Input() ${nameStringToVariableString(json.codeContext?.name)}Definition = "${json.definition ? | ||
json.definition : 'default tooltip message' }";`, | ||
outputs: ({ json }) => { | ||
const name = nameStringToVariableString(json.codeContext?.name); | ||
return `@Output() ${name}IsOpenChange = new EventEmitter<any>(); | ||
@Output() ${name}OnClose = new EventEmitter<any>(); | ||
@Output() ${name}OnOpen = new EventEmitter<any>();`; | ||
}, | ||
imports: ['TooltipModule'], | ||
code: ({ json }) => { | ||
const name = nameStringToVariableString(json.codeContext?.name); | ||
return `<ibm-tooltip-definition | ||
[isOpen]="${name}IsOpen" | ||
[align]="${name}Align" | ||
(onOpen)="${name}OnOpen.emit($event)" | ||
(onClose)="${name}OnClose.emit($event)" | ||
(isOpenChange)="${name}IsOpenChange.emit($event)" | ||
[description]="${name}Definition"> | ||
{{${name}Description}} | ||
</ibm-tooltip-definition>`; | ||
} | ||
} | ||
}, | ||
react: { | ||
latest: { | ||
imports: ['DefinitionTooltip'], | ||
code: ({ json }) => `<DefinitionTooltip | ||
${reactClassNamesFromComponentObj(json)} | ||
align="${json.alignment}" | ||
${json.isDefaultOpened ? `defaultOpen={${json.isDefaultOpened}}` : ''} | ||
definition="${json.definition ? json.definition : 'default tooltip message'}" | ||
${json.isOpenOnHover ? `openOnHover={${json.isOpenOnHover}}` : ''}> | ||
${json.description ? json.description : 'description'} | ||
</DefinitionTooltip>` | ||
}, | ||
v10: { | ||
imports: ['DefinitionTooltip'], | ||
code: ({ json }) => `<DefinitionTooltip | ||
${reactClassNamesFromComponentObj(json)} | ||
align="${json.alignment}" | ||
${json.isDefaultOpened ? `defaultOpen={${json.isDefaultOpened}}` : ''} | ||
definition="${json.definition ? json.definition : 'default tooltip message'}" | ||
${json.isOpenOnHover ? `openOnHover={${json.isOpenOnHover}}` : ''}> | ||
${json.description ? json.description : 'description'} | ||
</DefinitionTooltip>` | ||
} | ||
} | ||
} | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both frameworks description is a child, so why don't we do that here too? Meaning description wouldn't be part of the componentObj.description - instead we just let items render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we stick with support only text only for now