Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/rax-document/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.1.7

- Feature: support customize styles and scripts

## v0.1.6

- Chore: bundle script should add `crossorigin="anonymous"` default
2 changes: 1 addition & 1 deletion packages/rax-document/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rax-document",
"version": "0.1.6",
"version": "0.1.7",
"description": "Provide components for building Document",
"license": "BSD-3-Clause",
"main": "lib/index.js",
Expand Down
16 changes: 15 additions & 1 deletion packages/rax-document/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,22 @@ function Data(props, context) {
// Named by role rather than implementationm, so component name are `Style` rather than `Styles`.
function Style(props, context) {
const { __styles = [] } = context;
const consumer = getConsumer(props);

if (typeof consumer === 'function') {
return consumer(__styles);
}

return __styles.map((src, index) => <link {...props} rel="stylesheet" href={src} key={`style_${index}`} />);
}

function Script(props, context) {
const { __scripts = [] } = context;
const consumer = getConsumer(props);

if (typeof consumer === 'function') {
return consumer(__scripts);
}

// props such as type can be passed to script tag
// script default crossorigin value is anonymous
Expand All @@ -72,7 +82,7 @@ function App(props, context) {
return route.path == pagePath;
});

const consumer = Array.isArray(props.children) ? props.children[0] : props.children;
const consumer = getConsumer(props);

if (typeof consumer === 'function') {
return consumer(currentPageInfo);
Expand All @@ -81,6 +91,10 @@ function App(props, context) {
return props.children;
}

function getConsumer(props) {
return Array.isArray(props.children) ? props.children[0] : props.children
}

export {
Root,
Data,
Expand Down