-
-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CSS): export individual CSS files for all components (#3588)
* feat(CSS): export individual CSS files for all components * docs: update radio-tile * build: add buildComponentCSS * test: fix error tests * docs: update import guide for Accordion and VisuallyHidden * build: used postcss-prune-var and postcss-discard-empty * build: remove exclude * build: lint-ts * fix: add notes in RangeSlider less
- Loading branch information
Showing
282 changed files
with
1,319 additions
and
848 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useState } from 'react'; | ||
import { FaCheck, FaCopy } from 'react-icons/fa'; | ||
|
||
import { IconButton, IconButtonProps } from 'rsuite'; | ||
import copy from 'copy-to-clipboard'; | ||
|
||
interface CopyCodeButtonProps extends IconButtonProps { | ||
code: string; | ||
} | ||
|
||
function CopyCodeButton(props: CopyCodeButtonProps) { | ||
const [copied, setCopied] = useState(false); | ||
const { code, ...rest } = props; | ||
|
||
const handleClick = () => { | ||
setCopied(true); | ||
|
||
copy(code); | ||
|
||
setTimeout(() => { | ||
setCopied(false); | ||
}, 2000); | ||
}; | ||
|
||
return ( | ||
<IconButton | ||
{...rest} | ||
appearance="subtle" | ||
circle | ||
size="xs" | ||
className="copy-code-button" | ||
onClick={handleClick} | ||
icon={copied ? <FaCheck /> : <FaCopy />} | ||
/> | ||
); | ||
} | ||
|
||
export default CopyCodeButton; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import hljs from 'highlight.js/lib/core'; | ||
import javascript from 'highlight.js/lib/languages/javascript'; | ||
import bash from 'highlight.js/lib/languages/bash'; | ||
import CopyCodeButton from './CopyCodeButton'; | ||
|
||
hljs.registerLanguage('javascript', javascript); | ||
hljs.registerLanguage('bash', bash); | ||
|
||
function highlightCode(code: string, language = 'javascript') { | ||
return hljs.highlight(code, { language, ignoreIllegals: true }).value; | ||
} | ||
|
||
interface StaticCodeViewProps { | ||
code: string; | ||
language?: 'javascript' | 'bash'; | ||
} | ||
|
||
function StaticCodeView(props: StaticCodeViewProps) { | ||
const { code, language = 'javascript' } = props; | ||
return ( | ||
<div className="static-code-view"> | ||
<div className="rcv-highlight"> | ||
<pre | ||
dangerouslySetInnerHTML={{ | ||
__html: `<code class="${language}">` + highlightCode(code, language) + '</code>' | ||
}} | ||
/> | ||
<CopyCodeButton code={code} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default StaticCodeView; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.copy-code-button { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import { Nav } from 'rsuite'; | ||
import StaticCodeView from '../CodeView/StaticCodeView'; | ||
|
||
const unstyledComponents = [ | ||
'Schema', | ||
'DOMHelper', | ||
'Whisper', | ||
'SafeAnchor', | ||
'Affix', | ||
'utils', | ||
'internals', | ||
'CustomProvider', | ||
'locales', | ||
'MaskedInput' | ||
]; | ||
|
||
const defaultCommands = { | ||
main: '', | ||
individual: '' | ||
}; | ||
|
||
interface ImportGuideProps { | ||
name?: string; | ||
activeCommand?: keyof typeof defaultCommands; | ||
components?: string[]; | ||
hasCssComponents?: string[]; | ||
} | ||
|
||
function individualCode(components: string[], hasCssComponents: string[], name = 'rsuite') { | ||
let individual = components | ||
.map(component => `import ${component} from '${name}/${component}';`) | ||
.join('\r\n'); | ||
|
||
if (hasCssComponents.length > 0) { | ||
individual += | ||
'\r\n\r\n// (Optional) Import component styles. If you are using Less, import the `index.less` file. \r\n' + | ||
hasCssComponents | ||
.map(component => `import '${name}/${component}/styles/index.css';`) | ||
.join('\r\n'); | ||
} | ||
|
||
return individual; | ||
} | ||
|
||
function mainCode(components: string[], name = 'rsuite') { | ||
return `import { ${components.join(', ')} } from '${name}';`; | ||
} | ||
|
||
const ImportGuide = (props: ImportGuideProps) => { | ||
const { | ||
name = 'rsuite', | ||
activeCommand, | ||
components, | ||
hasCssComponents: hasCssComponentsProp | ||
} = props; | ||
const [active, setActive] = React.useState(activeCommand || 'main'); | ||
|
||
const hasCssComponents = | ||
hasCssComponentsProp || components.filter(component => !unstyledComponents.includes(component)); | ||
|
||
const main = mainCode(components, name); | ||
const individual = individualCode(components, hasCssComponents, name); | ||
const commands = { main, individual }; | ||
|
||
return ( | ||
<div style={{ marginTop: 16 }}> | ||
<Nav appearance="subtle" activeKey={active} onSelect={setActive}> | ||
<Nav.Item eventKey="main">Main</Nav.Item> | ||
<Nav.Item eventKey="individual">Individual</Nav.Item> | ||
</Nav> | ||
|
||
<StaticCodeView code={commands[active]} language="javascript" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ImportGuide; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ImportGuide from './ImportGuide'; | ||
|
||
export default ImportGuide; |
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
Oops, something went wrong.