-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! chore(react-keytips): draft implementation
- Loading branch information
1 parent
cf0ef38
commit 9e76165
Showing
9 changed files
with
232 additions
and
70 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
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
19 changes: 6 additions & 13 deletions
19
packages/react-keytips/src/components/Keytip/renderKeytip.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 |
---|---|---|
@@ -1,24 +1,17 @@ | ||
/** @jsxRuntime classic */ | ||
/** @jsx createElement */ | ||
|
||
import type { KeytipState } from './Keytip.types'; | ||
import { Tooltip } from '@fluentui/react-tooltip'; | ||
import type { KeytipSlots, KeytipState } from './Keytip.types'; | ||
import { assertSlots } from '@fluentui/react-utilities'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import { createElement } from '@fluentui/react-jsx-runtime'; | ||
|
||
/** | ||
* Render the final JSX of Keytip | ||
*/ | ||
export const renderKeytip_unstable = (state: KeytipState) => { | ||
const { visible, appearance, positioning, content } = state; | ||
|
||
return ( | ||
<Tooltip | ||
visible={visible} | ||
appearance={appearance} | ||
positioning={positioning} | ||
content={content} | ||
relationship="description" | ||
/> | ||
); | ||
assertSlots<KeytipSlots>(state); | ||
return state.shouldRenderTooltip ? ( | ||
<state.content>{state.content.children}</state.content> | ||
) : null; | ||
}; |
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
61 changes: 61 additions & 0 deletions
61
packages/react-keytips/src/components/Keytip/useKeytipStyles.styles.ts
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,61 @@ | ||
import { tokens, makeStyles, mergeClasses } from '@fluentui/react-components'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
import { KeytipSlots, KeytipState } from './Keytip.types'; | ||
|
||
export const keytipClassNames: SlotClassNames<KeytipSlots> = { | ||
content: 'fui-Keytip__content', | ||
}; | ||
|
||
/** | ||
* Styles for the tooltip | ||
*/ | ||
const useStyles = makeStyles({ | ||
root: { | ||
display: 'none', | ||
boxSizing: 'border-box', | ||
maxWidth: '240px', | ||
cursor: 'default', | ||
fontFamily: tokens.fontFamilyBase, | ||
fontSize: tokens.fontSizeBase200, | ||
lineHeight: tokens.lineHeightBase200, | ||
overflowWrap: 'break-word', | ||
borderRadius: tokens.borderRadiusMedium, | ||
border: `1px solid ${tokens.colorTransparentStroke}`, | ||
padding: '4px 11px 6px 11px', // '5px 12px 7px 12px' minus the border width '1px' | ||
backgroundColor: tokens.colorNeutralBackground1, | ||
color: tokens.colorNeutralForeground1, | ||
|
||
// TODO need to add versions of tokens.alias.shadow.shadow8, etc. that work with filter | ||
filter: | ||
`drop-shadow(0 0 2px ${tokens.colorNeutralShadowAmbient}) ` + | ||
`drop-shadow(0 4px 8px ${tokens.colorNeutralShadowKey})`, | ||
}, | ||
|
||
visible: { | ||
display: 'block', | ||
}, | ||
|
||
inverted: { | ||
backgroundColor: tokens.colorNeutralBackgroundStatic, | ||
color: tokens.colorNeutralForegroundStaticInverted, | ||
}, | ||
}); | ||
|
||
/** | ||
* Apply styling to the Tooltip slots based on the state | ||
*/ | ||
export const useKeytipStyles_unstable = (state: KeytipState): KeytipState => { | ||
'use no memo'; | ||
|
||
const styles = useStyles(); | ||
|
||
state.content.className = mergeClasses( | ||
keytipClassNames.content, | ||
styles.root, | ||
state.appearance === 'inverted' && styles.inverted, | ||
state.visible && styles.visible, | ||
state.content.className | ||
); | ||
|
||
return state; | ||
}; |
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.