Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
722 additions
and
383 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cosmos-export | ||
cosmos.userdeps.js | ||
booleanInputPlugin/dist |
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,4 @@ | ||
{ | ||
"name": "Boolean input", | ||
"ui": "dist/ui" | ||
} |
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,36 @@ | ||
import React from 'react'; | ||
|
||
type Props = { | ||
indentLevel: number; | ||
itemName: string; | ||
value: boolean; | ||
onChange: (value: boolean) => unknown; | ||
}; | ||
|
||
export function BooleanInput({ | ||
indentLevel, | ||
itemName, | ||
value, | ||
onChange, | ||
}: Props) { | ||
return ( | ||
<label | ||
style={{ | ||
display: 'flex', | ||
height: 28, | ||
marginLeft: indentLevel * 12 + 20, | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
userSelect: 'none', | ||
}} | ||
> | ||
<input | ||
style={{ marginRight: 8 }} | ||
type="checkbox" | ||
checked={value} | ||
onChange={e => onChange(e.target.checked)} | ||
/> | ||
{itemName} | ||
</label> | ||
); | ||
} |
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,31 @@ | ||
import React from 'react'; | ||
import { ValueInputSlotProps } from 'react-cosmos-playground2/plugin'; | ||
import { createPlugin } from 'react-plugin'; | ||
import { BooleanInput } from './BooleanInput'; | ||
|
||
type BooleanInputPluginSpec = { | ||
name: 'booleanInputPlugin'; | ||
}; | ||
|
||
const { plug, register } = createPlugin<BooleanInputPluginSpec>({ | ||
name: 'booleanInputPlugin', | ||
}); | ||
|
||
plug<ValueInputSlotProps>('valueInput', ({ slotProps, children }) => { | ||
const { item, itemName, parents, onInputChange } = slotProps; | ||
|
||
if (item.type === 'primitive' && typeof item.value === 'boolean') | ||
return ( | ||
<BooleanInput | ||
indentLevel={parents.length} | ||
itemName={itemName} | ||
value={item.value} | ||
onChange={onInputChange} | ||
/> | ||
); | ||
|
||
// Fall back to default inputs | ||
return <>{children}</>; | ||
}); | ||
|
||
register(); |
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 @@ | ||
const { join } = require('path'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
||
const src = join(__dirname, 'src'); | ||
const dist = join(__dirname, 'dist'); | ||
const env = process.env.NODE_ENV || 'development'; | ||
|
||
const plugins = []; | ||
|
||
module.exports = { | ||
mode: env, | ||
devtool: false, | ||
entry: join(src, 'ui.tsx'), | ||
output: { | ||
path: dist, | ||
filename: 'ui.js', | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.tsx', '.js'], | ||
}, | ||
externals: { | ||
'react-dom': 'ReactDom', | ||
'react-plugin': 'ReactPlugin', | ||
react: 'React', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.tsx?$/, | ||
include: src, | ||
use: { | ||
loader: 'babel-loader', | ||
}, | ||
}, | ||
], | ||
}, | ||
plugins, | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.