-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,64 @@ | ||
import { h, Component, createRef, type ComponentClass } from 'preact'; | ||
import { useCallback } from 'preact/hooks'; | ||
import HintFactory, { type ReactHintProps } from 'react-hint'; | ||
import { Component, createRef, type ComponentClass } from 'preact'; | ||
import type { ReactHintProps } from 'react-hint'; | ||
// @ts-expect-error @typescript-eslint/ban-ts-comment | ||
import HintFactory from 'react-hint/src'; | ||
|
||
import s from './styles.css'; | ||
import { useStoreon } from '../../store'; | ||
import { KEYS } from '../../constants'; | ||
import { FunctionName } from './FunctionName'; | ||
import { FunctionLocation } from './FunctionLocation'; | ||
import { CronExamplesTooltip } from './CronExamplesTooltip'; | ||
import cronExamples from './CronExamplesTooltip/cronExamples.json'; | ||
|
||
// @ts-expect-error @typescript-eslint/ban-ts-comment | ||
const Hint: ComponentClass<ReactHintProps> = HintFactory({ createElement: h, Component, createRef }); | ||
const delay = { | ||
const Hint: ComponentClass<ReactHintProps> = HintFactory({ Component, createRef }); | ||
|
||
const delay: ReactHintProps['delay'] = { | ||
show: 500, | ||
hide: 100, | ||
} as const; | ||
|
||
const dataList = cronExamples.map((i) => ( | ||
<option key={i.value} value={i.value}> | ||
{i.label} | ||
</option> | ||
)); | ||
}; | ||
|
||
export const Tooltips: FC = () => { | ||
const { items } = useStoreon('items'); | ||
const events: ReactHintProps['events'] = { | ||
focus: true, | ||
click: true, | ||
hover: false, | ||
}; | ||
|
||
const onRenderContent = useCallback((target: HTMLInputElement) => { | ||
switch (target.dataset.name) { | ||
case KEYS.functionLocation: { | ||
return ( | ||
<FunctionLocation target={target} /> | ||
); | ||
} | ||
case KEYS.functionName: { | ||
return ( | ||
<FunctionName target={target} /> | ||
); | ||
} | ||
case KEYS.cronExpression: { | ||
return ( | ||
<CronExamplesTooltip target={target} /> | ||
); | ||
} | ||
const onRenderContent = ((target: HTMLInputElement) => { | ||
switch (target.dataset.name) { | ||
case KEYS.functionLocation: { | ||
return ( | ||
<FunctionLocation target={target} /> | ||
); | ||
} | ||
case KEYS.functionName: { | ||
return ( | ||
<FunctionName target={target} /> | ||
); | ||
} | ||
return null; | ||
}, [items]); | ||
case KEYS.cronExpression: { | ||
return ( | ||
<CronExamplesTooltip target={target} /> | ||
); | ||
} | ||
} | ||
return null; | ||
}) as unknown as ReactHintProps['onRenderContent']; | ||
|
||
return ( | ||
<> | ||
<Hint events delay={delay} /> | ||
<Hint | ||
persist | ||
attribute="data-fl" | ||
events={{ | ||
focus: true, | ||
click: true, | ||
hover: false, | ||
}} | ||
className={s.fs} | ||
// @ts-expect-error @typescript-eslint/ban-ts-comment | ||
onRenderContent={onRenderContent} | ||
/> | ||
<datalist id="cron-examples"> | ||
{dataList} | ||
</datalist> | ||
</> | ||
); | ||
}; | ||
export const Tooltips: FC = () => | ||
<> | ||
<Hint events delay={delay} /> | ||
<Hint | ||
persist | ||
attribute="data-fl" | ||
events={events} | ||
className={s.fs} | ||
onRenderContent={onRenderContent} | ||
/> | ||
<datalist id="cron-examples"> | ||
{cronExamples.map((i) => | ||
<option key={i.value} value={i.value}> | ||
{i.label} | ||
</option> | ||
)} | ||
</datalist> | ||
</>; |
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