Skip to content

Instantly share code, notes, and snippets.

View yujonglee's full-sized avatar

yujonglee yujonglee

View GitHub Profile
@yujonglee
yujonglee / custom_hook.js
Last active August 30, 2021 10:18
Calling function component is like custom hook.
function A() {
const [state] = useState([])
return (
<div>{state}</div>
)
}
A()
<A />
@yujonglee
yujonglee / cloneElement_basic.js
Last active September 3, 2021 09:49
dooboo-ui styling
const Container = () => {
const [isOutlined, setIsOutlined] = useState(false);
const [isDisabled, setIsDisabled] = useState(false);
return (
<>
<Button
type="info"
text={isDisabled ? "Disabled: true" : "Disabled: false"}
style={{ margin: 10 }}
@yujonglee
yujonglee / cloneElement.js
Created September 1, 2021 13:11
How cloneElement works.
React.cloneElement(
element,
[props],
[...children]
)
<element.type {...element.props} {...props}>{children}</element.type>
@yujonglee
yujonglee / editable.js
Created September 1, 2021 13:38
Editable wrapper
const Editable = ({ children }) => {
const [isEditing, setIsEditing] = useState(false);
return (
<FieldContainer>
{React.Children.map(children, (child) =>
React.cloneElement(child, { isEditing })
)}
<Button
@yujonglee
yujonglee / selectable.js
Created September 1, 2021 13:58
Selectable wrapper
const Selectable = ({children, onPress, mode = "singleChoice"}) => {
const initial = React.Children.map(
children ?? [],
(child) => !!child.props.checked
);
const [checkedArray, setCheckedArray] = useState(initial);
const [checkedIndex, setCheckedIndex] = useState(
initial.findIndex((value) => value === true)
@yujonglee
yujonglee / singleChoice.js
Last active September 2, 2021 02:52
Selectable example
const SingleChoice = () => {
const [value, setValue] = useState("2");
return (
<Container>
<Selectable mode="singleChoice" onPress={setValue}>
<Checkbox type="primary" checked={false} />
<Checkbox type="secondary" checked={false} />
<Checkbox type="success" checked={true} />
<Checkbox type="warning" checked={false} />
@yujonglee
yujonglee / submittable.js
Created September 2, 2021 10:22
Submittable wrapper
const Submittable = ({ children }) => {
const refs = Array(children.length).fill(null).map(useRef);
return React.Children.map(children, (child, i) => {
const isLast = i === children.length - 1;
return React.cloneElement(child, {
inputRef: refs[i],
onSubmitEditing: !isLast ? () => refs[i + 1].current.focus() : undefined
});
import { generatorHandler } from '@prisma/generator-helper';
generatorHandler({
onManifest() {
return {
defaultOutput: './schema',
prettyName: 'GraphQL-Schema-Generator',
};
},
async onGenerate(options) {
@yujonglee
yujonglee / GeneratorOptions.ts
Created December 16, 2021 06:47
GeneratorOptions.ts
export declare type GeneratorOptions = {
generator: GeneratorConfig;
otherGenerators: GeneratorConfig[];
schemaPath: string;
dmmf: DMMF.Document;
datasources: DataSource[];
datamodel: string;
version: string;
binaryPaths?: BinaryPaths;
};
@yujonglee
yujonglee / converter.ts
Created December 22, 2021 04:42
simplified converter in graphql-schema-generator
const convertedType = rules.reduce(
(type, {matcher, transformer}: Rule): string => {
if (!matcher(field, model)) {
return type;
}
return transformer(field, type);
},
initialType,
);