mirror of
https://github.com/zhigang1992/react.git
synced 2026-01-24 20:57:51 +08:00
* feat(scaleable): add scaleable props to each component * chore(scaleable): update the exported type * feat: apply scaleable to components chore: remove with-default test: improve testcase for scaleable chore: resolve test warning ci: upgrade nodejs to latest lts docs: fix type error in document site * docs: update documents to be compatible with scaleable chore: fix build errors * chore: remove all size-related attributes docs: improve guide document * docs: add scaleable documentation test: update snapshots chore: remove unused * feat: add scaleable to grid components * docs: improve docs * test: update snapshots * fix(grid): fix basic component props
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import React from 'react'
|
|
import useScaleable, { withScaleable } from '../use-scaleable'
|
|
|
|
interface Props {
|
|
block?: boolean
|
|
className?: string
|
|
}
|
|
|
|
const defaultProps = {
|
|
block: false,
|
|
className: '',
|
|
}
|
|
|
|
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
|
|
export type CodeProps = Props & NativeAttrs
|
|
|
|
const CodeComponent: React.FC<React.PropsWithChildren<CodeProps>> = ({
|
|
children,
|
|
block,
|
|
className,
|
|
...props
|
|
}: React.PropsWithChildren<CodeProps> & typeof defaultProps) => {
|
|
const { SCALES } = useScaleable()
|
|
|
|
if (!block) return <code {...props}>{children}</code>
|
|
|
|
return (
|
|
<>
|
|
<pre className={className} {...props}>
|
|
<code>{children}</code>
|
|
</pre>
|
|
<style jsx>{`
|
|
pre {
|
|
max-width: 100%;
|
|
font-size: ${SCALES.font(0.875)};
|
|
width: ${SCALES.width(1, 'initial')};
|
|
height: ${SCALES.height(1, 'auto')};
|
|
padding: ${SCALES.pt(1)} ${SCALES.pr(1.3)} ${SCALES.pb(1)} ${SCALES.pl(1.3)};
|
|
margin: ${SCALES.mt(1.3)} ${SCALES.mr(0)} ${SCALES.mb(1.3)} ${SCALES.ml(0)};
|
|
}
|
|
|
|
.dark {
|
|
color: white;
|
|
background: black;
|
|
}
|
|
|
|
.dark code {
|
|
color: white;
|
|
}
|
|
`}</style>
|
|
</>
|
|
)
|
|
}
|
|
|
|
CodeComponent.defaultProps = defaultProps
|
|
CodeComponent.displayName = 'GeistCode'
|
|
const Code = withScaleable(CodeComponent)
|
|
export default Code
|