umijs / dumi

📖 Static Site Generator for component library development
https://d.umijs.org
MIT License
3.54k stars 1.17k forks source link

能否优雅地全局隐藏 codesandbox 按钮? #799

Closed Gavin-Gong closed 3 years ago

Gavin-Gong commented 3 years ago

能否优雅地全局隐藏 codesandbox 按钮?因为像内部项目和 react-native 项目是不需要 codesandbox 的 image

workaround

PeachScript commented 3 years ago

本地自定义 Previewer,props 加上 hideActions 再传给 dumi 默认主题的 Previewer 渲染,参考:https://d.umijs.org/zh-CN/theme/development

Gavin-Gong commented 3 years ago

本地自定义 Previewer,props 加上 hideActions 再传给 dumi 默认主题的 Previewer 渲染,参考:https://d.umijs.org/zh-CN/theme/development

按照你说的方法解决了我的问题,thx。其实更加期望可以在 themeConfig 下增加一个字段方便进行控制。因为在我看来不使用codesandbox 是比较常见的场景🙂。

import Previewer from 'dumi-theme-default/src/builtins/Previewer';

export default (props) => {
  return <Previewer {...props} hideActions="CSB" />;
};
PeachScript commented 3 years ago

其实更加期望可以在 themeConfig 下增加一个字段方便进行控制。因为在我看来不使用codesandbox 是比较常见的场景🙂。

@Gavin-Gong 有空可以来个 PR 支持下~

fariellany commented 2 years ago

Previewer

应该怎么写呢 ? 我是用 code src 的 不是直接用的 我应该怎么把 Previewer导入到我全局里面呢

import React from 'react'; import Layout from 'dumi-theme-default/es/layout';

export default ({ children, ...props }) => ( <Layout {...props}> <> {children} </> );

直接是写在这里面吗 ?

BosenY commented 8 months ago

我更新下最新版本的隐藏方法:

PeachScript commented 8 months ago

@BosenY 感谢补充,有两点建议:

  1. 本地主题建议用 theme-original 别名,这样不需要关心当前是什么主题包:https://d.umijs.org/theme#dumitheme-originallayoutsbuiltinsslotsxx
  2. 建议覆盖 PreviewerActions slot 而不是覆盖 Previewer builtin,符合最小变更