Skip to content

Commit

Permalink
style:调整案例样式
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed May 9, 2022
1 parent 63d3360 commit 248cbba
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion website/src/components/CodeLayout/assets/expand.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion website/src/components/CodeLayout/assets/unexpand.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions website/src/components/CodeLayout/code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import Codesandbox from './codesandbox';
import Stackblitz from './stackblitz';
import Codepen from './codepen';
const Code = (props: CodeProps) => {
const { code, copyNodes, codePenOptions, codeSandboxOptions, stackBlitzOptions, language } = props;
const { code, copyNodes, codePenOptions, codeSandboxOptions, stackBlitzOptions, language, codePadding } = props;
const style = React.useMemo(() => {
if (typeof codePadding) {
return { padding: codePadding };
}
return {};
}, [codePadding]);
const [show, setShow] = React.useState(false);
return (
<React.Fragment>
Expand All @@ -17,7 +23,7 @@ const Code = (props: CodeProps) => {
<Copy copyNodes={copyNodes} />
<ShowHide show={show} onClick={setShow} />
</div>
<div className={`preview-code preview-code-${show}`}>
<div className={`preview-code preview-code-${show}`} style={style}>
<pre className={`language-${language}`}>{code}</pre>
</div>
</React.Fragment>
Expand Down
29 changes: 19 additions & 10 deletions website/src/components/CodeLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './styles/index.css';
export * from './interface';
const Preview = (props: PreviewProps) => {
const {
prefixCls = 'w-code-layout',
code,
className = '',
copyNodes = '',
Expand All @@ -13,19 +14,27 @@ const Preview = (props: PreviewProps) => {
stackBlitzOptions,
previewBodyClassName,
language = 'jsx',
customButton,
bordered = true,
noCode = false,
codePadding = 0,
...rest
} = props;
return (
<div className={`preview-fieldset ${className}`}>
<div {...rest} className={`preview-body ${previewBodyClassName}`} />
<Code
language={language}
codePenOptions={codePenOptions}
codeSandboxOptions={codeSandboxOptions}
stackBlitzOptions={stackBlitzOptions}
code={code}
copyNodes={copyNodes}
/>
<div className={`${prefixCls} ${prefixCls}-body-${bordered} ${className}`}>
<div {...rest} className={`preview preview-body-${bordered} ${previewBodyClassName}`} />
{!noCode && (
<Code
codePadding={codePadding}
customButton={customButton}
language={language}
codePenOptions={codePenOptions}
codeSandboxOptions={codeSandboxOptions}
stackBlitzOptions={stackBlitzOptions}
code={code}
copyNodes={copyNodes}
/>
)}
</div>
);
};
Expand Down
9 changes: 9 additions & 0 deletions website/src/components/CodeLayout/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ export interface CodeProps {
codeSandboxOptions?: CodeSandboxProps;
/** stackBlitz参数 **/
stackBlitzOptions?: StackBlitzProps;
/* 自定义操作按钮 **/
customButton?: React.ReactNode;
/** 展示代码块内边距 **/
codePadding?: number;
}

export interface PreviewProps extends CodeProps {
previewBodyClassName?: string;
className?: string;
children?: React.ReactNode;
prefixCls?: string;
/** 只显示效果 **/
noCode?: boolean;
/** 是否需要边框 */
bordered?: boolean;
}
79 changes: 28 additions & 51 deletions website/src/components/CodeLayout/styles/index.css
Original file line number Diff line number Diff line change
@@ -1,90 +1,67 @@
.preview-fieldset {
margin: 0px;
padding: 0px;
.w-code-layout {
border: 1px solid rgba(0, 0, 0, 0.06);
border-radius: 5px;
background-color: #fff;
}

.preview-body {
padding: 10px;
.w-code-layout.w-code-layout-body-false {
border: none;
}
.w-code-layout .preview {
padding: 16px;
}

.w-code-layout .preview-body-false {
padding-left: 0px;
}

.preview-button {
padding: 5px;
.w-code-layout .preview-button {
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid rgba(0, 0, 0, 0.06);
}
.preview-button .preview-button-ccs {
margin-right: 30px;
}
.preview-button .preview-button-ccs button {
border: none;
background-color: transparent;
display: flex;
align-items: center;
opacity: 0.5;
padding-left: 0;
padding-right: 0;
}
.preview-button .preview-button-ccs button:hover {
opacity: 1;
padding: 10px 0px;
}

.preview-button-span {
.w-code-layout .preview-button .preview-button-span {
margin-right: 30px;
display: flex;
align-items: center;
justify-content: center;
}

.preview-button-copy {
opacity: 0.5;
cursor: pointer;
}

.preview-button-copy:hover {
opacity: 1;
}
.preview-button-copy > .copy {
.w-code-layout .preview-button .preview-button-copy > .copy {
display: inline-block;
}
.preview-button-copy > .check {
.w-code-layout .preview-button .preview-button-copy > .check {
display: none;
}

.preview-button-copy-active > .copy {
.w-code-layout .preview-button .preview-button-copy-active > .copy {
display: none;
}

.preview-button-copy-active > .check {
.w-code-layout .preview-button .preview-button-copy-active > .check {
display: inline-block;
}
.preview-fieldset .preview-code > pre {
margin-bottom: 0px;
}

.preview-code-false {
display: none;
}

.preview-code-true {
display: block;
.w-code-layout .preview-button .preview-button-span:hover {
opacity: 1;
}

.preview-button .preview-code-exand-unexpand-icon {
opacity: 0.5;
.w-code-layout .preview-button .preview-code-exand-unexpand-icon-true {
display: inline-block;
cursor: pointer;
}
.preview-button .preview-code-exand-unexpand-icon:hover {
opacity: 1;

.w-code-layout .preview-button .preview-code-exand-unexpand-icon-false {
display: none;
}

.preview-button .preview-code-exand-unexpand-icon .preview-code-exand-unexpand-icon-false {
.w-code-layout .preview-code.preview-code-false {
display: none;
}
.preview-button .preview-code-exand-unexpand-icon .preview-code-exand-unexpand-icon-true {
display: inline-block;

.w-code-layout .preview-code {
background-color: #f6f8fa;
}
2 changes: 1 addition & 1 deletion website/src/pages/example/App.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Alert } from "uiw";
// or
import Alert from "@uiw/react-alert";
```
`import React from 'react'`

## Basic Usage

```jsx mdx:preview
Expand Down

0 comments on commit 248cbba

Please sign in to comment.