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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = {
port: 9000,
openBrowser: true,
paramType: 'search', // default is 'hash'
includeIndex: true, // default is false, explicitly includes 'index.html' in links.
exampleCode: `
<Button>
Hello World!
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface PlayroomConfig {
baseUrl?: string;
paramType: 'hash' | 'search';
iframeSandbox?: string;
includeIndex?: boolean;
}

interface InternalPlayroomConfig extends PlayroomConfig {
Expand Down
1 change: 1 addition & 0 deletions src/utils/usePreviewUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export default (theme: string) => {
code,
theme: isThemed ? theme : undefined,
paramType: playroomConfig.paramType,
includeIndex: playroomConfig.includeIndex,
});
};
2 changes: 2 additions & 0 deletions utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface CreateUrlOptions {
themes?: string[];
widths?: number[];
paramType?: ParamType;
includeIndex?: boolean;
}

export const createUrl: (options: CreateUrlOptions) => string;
Expand All @@ -31,6 +32,7 @@ interface CreatePreviewUrlOptions {
code?: string;
theme?: string;
paramType?: ParamType;
includeIndex?: boolean;
}

export const createPreviewUrl: (options: CreatePreviewUrlOptions) => string;
25 changes: 21 additions & 4 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ const compressParams = ({ code, themes, widths, theme }) => {
return lzString.compressToEncodedURIComponent(data);
};

const createUrl = ({ baseUrl, code, themes, widths, paramType = 'hash' }) => {
const createUrl = ({
baseUrl,
code,
themes,
widths,
paramType = 'hash',
includeIndex = false,
}) => {
let path = '';

if (code || themes || widths) {
const compressedData = compressParams({ code, themes, widths });

path = `${paramType === 'hash' ? '#' : ''}?code=${compressedData}`;
path = `${includeIndex ? '/index.html' : ''}${
paramType === 'hash' ? '#' : ''
}?code=${compressedData}`;
}

if (baseUrl) {
Expand All @@ -29,13 +38,21 @@ const createUrl = ({ baseUrl, code, themes, widths, paramType = 'hash' }) => {
return path;
};

const createPreviewUrl = ({ baseUrl, code, theme, paramType = 'hash' }) => {
const createPreviewUrl = ({
baseUrl,
code,
theme,
paramType = 'hash',
includeIndex = false,
}) => {
let path = '';

if (code || theme) {
const compressedData = compressParams({ code, theme });

path = `/preview${paramType === 'hash' ? '#' : ''}?code=${compressedData}`;
path = `/preview${includeIndex ? '/index.html' : ''}${
paramType === 'hash' ? '#' : ''
}?code=${compressedData}`;
}

if (baseUrl) {
Expand Down