-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:secjs/Generator
- Loading branch information
Showing
72 changed files
with
321 additions
and
18 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
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.
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.
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.
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.
22 changes: 22 additions & 0 deletions
22
app/templates/reactjs/reactjsComponent/components/__name__/component.tsx.txt
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,22 @@ | ||
import React from 'react'; | ||
|
||
interface Props { | ||
title: string; | ||
} | ||
|
||
const <%= namePascal %> = ({title}: Props): JSX.Element => { | ||
const [data, setData] = React.useState<boolean>(false) | ||
|
||
const handleClick = React.useCallback(() => { | ||
setData(data => !data) | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<h1>{title}</h1> | ||
<button onClick={handleClick}>Click Me!</button> | ||
</div> | ||
); | ||
} | ||
|
||
export default <%= namePascal %> |
1 change: 1 addition & 0 deletions
1
app/templates/reactjs/reactjsComponent/components/__name__/index.tsx.txt
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 @@ | ||
export { default } from './' |
71 changes: 71 additions & 0 deletions
71
app/templates/reactjs/reactjsContext/contexts/__name__Context.tsx.txt
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,71 @@ | ||
import { createContext, useContext, useReducer } from 'react'; | ||
|
||
interface <%= namePascal %> { | ||
id: number; | ||
title: string; | ||
} | ||
|
||
interface <%= namePascal %>State { | ||
<%= namePluralCamel %>: <%= namePascal %>[]; | ||
} | ||
|
||
interface Action { | ||
type: 'ADD' | 'DELETE'; | ||
<%= nameCamel %>: <%= namePascal %>; | ||
id: string; | ||
} | ||
|
||
const <%= namePascal %>StateContext = createContext<<%= namePascal %>State>({ | ||
<%= nameCamel %>: [], | ||
}); | ||
|
||
const <%= namePascal %>DispatchContext = createContext<React.Dispatch<Action>>( | ||
null as unknown as React.Dispatch<Action>, | ||
); | ||
|
||
function <%= namePascal %>Reducer(state: <%= namePascal %>State, action: Action) { | ||
switch (action.type) { | ||
case 'ADD': { | ||
return { | ||
...state, | ||
<%= nameCamel %>: [...state.<%= namePluralCamel %>, action.<%= nameCamel %>], | ||
}; | ||
} | ||
case 'DELETE': { | ||
const updated<%= namePascal %> = state.<%= namePluralCamel %>.filter((item) => item.id != action.id); | ||
return { | ||
...state, | ||
<%= namePluralCamel %>: updated<%= namePascal %>, | ||
}; | ||
} | ||
default: { | ||
throw new Error('unhandled action type'); | ||
} | ||
} | ||
} | ||
|
||
interface <%= namePascal %>Provider { | ||
children: React.ReactNode; | ||
} | ||
|
||
/* | ||
Use the <%= namePascal %>ContextProvider to wrap your app and set up the <%= namePascal %>StateContext and <%= namePascal %>DispatchContext. | ||
*/ | ||
|
||
export function <%= namePascal %>ContextProvider({ children }: <%= namePascal %>Provider): JSX.Element { | ||
const [state, dispatch] = useReducer(<%= namePascal %>Reducer, { | ||
<%= namePluralPascal %>: [], | ||
}); | ||
|
||
return ( | ||
<<%= namePascal %>StateContext.Provider value={state}> | ||
<<%= namePascal %>DispatchContext.Provider value={dispatch}> | ||
{children} | ||
</<%= namePascal %>DispatchContext.Provider> | ||
</<%= namePascal %>StateContext.Provider> | ||
); | ||
} | ||
|
||
export const use<%= namePascal %>DispatchContext = (): React.Dispatch<Action> => | ||
useContext(<%= namePascal %>DispatchContext); | ||
export const use<%= namePascal %>StateContext = (): <%= namePascal %>State => useContext(<%= namePascal %>StateContext); |
10 changes: 10 additions & 0 deletions
10
app/templates/reactjs/reactjsHook/hooks/use__name__.tsx.txt
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,10 @@ | ||
import { Reducer, useReducer } from 'react'; | ||
|
||
const <%= namePascal %>Reducer = (state: boolean, nextValue?: any) => | ||
typeof nextValue === 'boolean' ? nextValue : !state; | ||
|
||
const use<%= namePascal %> = (initialValue: boolean): [boolean, (nextValue?: any) => void] => { | ||
return useReducer<Reducer<boolean, any>>(<%= namePascal %>Reducer, initialValue); | ||
}; | ||
|
||
export default use<%= namePascal %>; |
35 changes: 35 additions & 0 deletions
35
app/templates/reactjs/reactjsMui/components/__name__/component.tsx.txt
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,35 @@ | ||
import * as React from 'react'; | ||
import { styled } from '@mui/material/styles'; | ||
import Button from '@mui/material/Button'; | ||
import Stack from '@mui/material/Stack'; | ||
import { purple } from '@mui/material/colors'; | ||
|
||
const ColorButton = styled(Button)(({ theme }) => ({ | ||
color: theme.palette.getContrastText(purple[500]), | ||
backgroundColor: purple[500], | ||
'&:hover': { | ||
backgroundColor: purple[700], | ||
}, | ||
})); | ||
|
||
interface Props { | ||
title: string; | ||
} | ||
|
||
const <%= namePascal %> = ({title}: Props): JSX.Element => { | ||
const [data, setData] = React.useState<boolean>(false) | ||
|
||
const handleClick = React.useCallback(() => { | ||
setData(data => !data) | ||
}, []); | ||
|
||
return ( | ||
<Stack spacing={2} direction="row"> | ||
<ColorButton variant="contained" onClick={handleClick}> | ||
{title} | ||
</ColorButton> | ||
</Stack> | ||
); | ||
} | ||
|
||
export default <%= namePascal %> |
1 change: 1 addition & 0 deletions
1
app/templates/reactjs/reactjsMui/components/__name__/index.tsx.txt
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 @@ | ||
export { default } from './' |
28 changes: 28 additions & 0 deletions
28
app/templates/reactjs/reactjsStyled/components/__name__/component.tsx.txt
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,28 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components' | ||
|
||
const Button = styled.button` | ||
/* ... */ | ||
` | ||
|
||
interface Props { | ||
title: string; | ||
} | ||
|
||
const <%= namePascal %> = ({title}: Props): JSX.Element => { | ||
const [data, setData] = React.useState<boolean>(false) | ||
|
||
const handleClick = React.useCallback(() => { | ||
setData(data => !data) | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<Button onClick={handleClick}> | ||
{title} | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
export default <%= namePascal %> |
1 change: 1 addition & 0 deletions
1
app/templates/reactjs/reactjsStyled/components/__name__/index.tsx.txt
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 @@ | ||
export { default } from './' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const helpers = require('yeoman-test') | ||
const assert = require('yeoman-assert') | ||
|
||
describe('\n ReactJS Component ⚛️', () => { | ||
beforeAll(() => { | ||
return helpers | ||
.run(path.join(__dirname, '../../app')) | ||
.withOptions({ path: './Foo' }) | ||
.withArguments('Bar') | ||
.withPrompts({ framework: 'reactjs', template: 'reactjsComponent' }) | ||
}) | ||
|
||
it('should create all files from resource Bar in folder Foo', () => { | ||
assert.file([ | ||
'./Foo/components/Bar/component.tsx', | ||
'./Foo/components/Bar/index.tsx', | ||
]) | ||
}) | ||
}) |
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,19 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const helpers = require('yeoman-test') | ||
const assert = require('yeoman-assert') | ||
|
||
describe('\n ReactJS Context ⚛️', () => { | ||
beforeAll(() => { | ||
return helpers | ||
.run(path.join(__dirname, '../../app')) | ||
.withOptions({ path: './Foo' }) | ||
.withArguments('Bar') | ||
.withPrompts({ framework: 'reactjs', template: 'reactjsContext' }) | ||
}) | ||
|
||
it('should create all files from resource Bar in folder Foo', () => { | ||
assert.file(['./Foo/contexts/BarContext.tsx']) | ||
}) | ||
}) |
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,19 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const helpers = require('yeoman-test') | ||
const assert = require('yeoman-assert') | ||
|
||
describe('\n ReactJS Hook ⚛️', () => { | ||
beforeAll(() => { | ||
return helpers | ||
.run(path.join(__dirname, '../../app')) | ||
.withOptions({ path: './Foo' }) | ||
.withArguments('Bar') | ||
.withPrompts({ framework: 'reactjs', template: 'reactjsHook' }) | ||
}) | ||
|
||
it('should create all files from resource Bar in folder Foo', () => { | ||
assert.file(['./Foo/hooks/useBar.tsx']) | ||
}) | ||
}) |
Oops, something went wrong.