-
Notifications
You must be signed in to change notification settings - Fork 41
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
14 changed files
with
176 additions
and
104 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
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
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,14 +1,30 @@ | ||
import React from "react" | ||
import { addDisposer } from "mobx-state-tree" | ||
import React, { useCallback } from "react" | ||
import { observer } from "mobx-react-lite" | ||
import { ComponentTitleBar } from "../component-title-bar" | ||
import { isAliveSafe } from "../../utilities/mst-utils" | ||
import t from "../../utilities/translation/translate" | ||
import { ITileTitleBarProps } from "../tiles/tile-base-props" | ||
import { isSliderModel } from "./slider-model" | ||
|
||
export const SliderTitleBar = observer(function SliderTitleBar({ tile, ...others }: ITileTitleBarProps) { | ||
const sliderModel = isSliderModel(tile?.content) ? tile?.content : undefined | ||
const getTitle = () => tile?.title || sliderModel?.name || t("DG.DocumentController.sliderTitle") | ||
export const SliderTitleBar = observer(function SliderTitleBar({ tile, onCloseTile, ...others }: ITileTitleBarProps) { | ||
const { content } = tile || {} | ||
|
||
const getTitle = useCallback(() => { | ||
const { title } = tile || {} | ||
const sliderModel = isAliveSafe(content) && isSliderModel(content) ? content : undefined | ||
const { name } = sliderModel || {} | ||
return title || name || t("DG.DocumentController.sliderTitle") | ||
}, [content, tile]) | ||
|
||
const handleCloseTile = useCallback((tileId: string) => { | ||
const sliderModel = isAliveSafe(content) && isSliderModel(content) ? content : undefined | ||
// when tile is closed by user, destroy the underlying global value as well | ||
sliderModel && addDisposer(sliderModel, () => sliderModel.destroyGlobalValue()) | ||
onCloseTile?.(tileId) | ||
}, [content, onCloseTile]) | ||
|
||
return ( | ||
<ComponentTitleBar tile={tile} getTitle={getTitle} {...others} /> | ||
<ComponentTitleBar tile={tile} getTitle={getTitle} onCloseTile={handleCloseTile} {...others} /> | ||
) | ||
}) |
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.