Custom Welcome Screen #1615
Replies: 14 comments 1 reply
-
This is a good idea and something I'm open to adding support for. It could be added as a plugin, however this raises the barrier to entry a bit because you need to package a Cosmos plugin to change the home screen. Another open is to select one of your fixtures as the welcome screen. Is this what you're envisioning? Btw, you can already set an initial fixture in your Cosmos config, which will auto open when you load Cosmos. This isn't a complete solution as you'll still see Cosmos' welcome screen when you close the fixture, but it might provide some instant value for you. |
Beta Was this translation helpful? Give feedback.
-
I do think a plugin would be nice, it does raise the barrier to entry but still a doable solution. Currently I'm using initial fixture but I like the idea of having a page that only shows once. |
Beta Was this translation helpful? Give feedback.
-
Just pushed a change that exposes a Haven't pushed a release yet but you can use it by installing the following canary version: Here are the steps you need to take to create this plugin:
{
"name": "Custom Home Overlay",
"ui": "dist/ui.js"
}
import React from 'react';
import { createPlugin } from 'react-plugin';
const { plug, register } = createPlugin({
name: 'customHomeOverlay',
});
plug('homeOverlay', () => {
return (
<div
style={{
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
background: '#fff',
}}
>
Hello World!
</div>
);
});
register();
import path from 'path';
import { fileURLToPath } from 'url';
const pluginRoot = fileURLToPath(new URL('.', import.meta.url));
const entry = path.join(pluginRoot, 'ui.tsx');
const outputPath = path.join(pluginRoot, 'dist');
export default {
mode: 'development',
devtool: false,
entry,
output: {
path: outputPath,
filename: 'ui.js',
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
compilerOptions: { noEmit: false },
},
},
],
},
externals: {
'react-plugin': 'ReactPlugin',
react: 'React',
},
};
@tsanyqudsi Let me know how this works for you. Based on your feedback I'll make this the official way to override the home screen and publish documentation for this approach. Thanks! |
Beta Was this translation helpful? Give feedback.
-
where do I get is it from here ? |
Beta Was this translation helpful? Give feedback.
-
Yes, that's the package. But you shouldn't bundle it with your plugin. The key for that is the Another example: |
Beta Was this translation helpful? Give feedback.
-
it doesn't work. Basically the plugin is detected, but it does nothing.
|
Beta Was this translation helpful? Give feedback.
-
Update :
Most probably it's because of the monorepo setup. You think I should put an issue on this part ? |
Beta Was this translation helpful? Give feedback.
-
@tsanyqudsi Monorepo setup should be ok. Yeah, feel free to create an issue and I'll investigate what's wrong. But before we do further investigation, is there a file generated at |
Beta Was this translation helpful? Give feedback.
-
My bad, the monorepo setup is fine, I screw up with cjs. Now the problem is with the externalized packages. When I do it shows But when I don't put the config
|
Beta Was this translation helpful? Give feedback.
-
I gave up lol. Maybe it's me or |
Beta Was this translation helpful? Give feedback.
-
@tsanyqudsi I don't think
I advice you try my webpack example or convert it to Vite if you're more comfortable. Alternatively, you can just put this in your source code instead: const { React, ReactPlugin } = window;
import { createPlugin } from ReactPlugin;
const { plug, register } = createPlugin({
name: 'customHomeOverlay',
});
plug('homeOverlay', () => {
return (
<div
style={{
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
background: '#fff',
}}
>
Hello World!
</div>
);
});
register(); But it's not as pretty as you need to convince TypeScript that React and ReactPlugin are attached to the global window object. |
Beta Was this translation helpful? Give feedback.
-
Tried vite, somehow same result. I stumbled with the comment here so I installed webpack and it's working like a charm. Based on my somehow headbanging experience, I do have few feedbacks.
Oh, could you republish react-plugin someday ? I'm rebuilding my Visual Novel engine and i'm interested to use react-plugin since the idea is quite nice. :P |
Beta Was this translation helpful? Give feedback.
-
Looking good! :D
Just remembered, here's an example of how someone else configured this using tsup: https://github.com/birchill/react-cosmos-dark-mode/blob/1b6667985a3d7aee7ddbecbf03a1b1acde3822fe/tsup.index.config.ts#L9-L15 So you might be able to get rid of webpack after all.
The last thing I want is to provide config options for small customizations like this. It will blow up the API surface area and introduce conflicts between features and between versions, etc. That said, you can do everything you want using plugins. After all the entire Cosmos UI is just plugins plugging into plugins. So you could extend the left nav and hide it when a fixture isn't selected, etc. But it's not trivial as you need to get intimate with the built-in Cosmos plugins: https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-ui/src/plugins I can help with pointers if you're interested in delving deeper but understand this isn't something well documented and it won't be obvious which slot to plug into or what methods you can call from what plugin. But each plugin has a clear spec like this one: https://github.com/react-cosmos/react-cosmos/blob/main/packages/react-cosmos-ui/src/plugins/FixtureTree/spec.ts so in theory it's not impossible to navigate the Cosmos UI internals on your own.
I want to make But that said the API is documented here https://reactcosmos.org/docs/plugins/ui-plugins and the Cosmos UI has been using this plugin API for years so it's pretty stable, too. |
Beta Was this translation helpful? Give feedback.
-
Damn.. so I need to use esbuild plugin and makesure it's production lol. You might want to add it to documentation someday. I think it's time to close the discussion. Will open a new one for customizing the welcome screen. |
Beta Was this translation helpful? Give feedback.
-
It would be nice if we could make our own welcome screen instead of the default one.
Beta Was this translation helpful? Give feedback.
All reactions