Skip to content

Commit

Permalink
Merge pull request #28 from sudoaugustin/alpha
Browse files Browse the repository at this point in the history
fix: portal
  • Loading branch information
sudoaugustin committed Oct 16, 2023
2 parents 07ba2b0 + 11f3d78 commit 6028266
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn test && yarn build && cd tests-ssr && yarn build
yarn build && yarn test && cd tests-ssr
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"build:dts": "tsc -p tsconfig.build.json --outDir ./dts",
"build:esm": "esbuild ./src/*.tsx ./src/**/*.ts --format=esm --outdir=./esm",
"build:cjs": "esbuild ./src/*.tsx ./src/**/*.ts --format=cjs --outdir=./cjs",
"publish:local": "yarn build && yarn unpublish:local && yarn link && yarn link --cwd node_modules/react && yarn link --cwd node_modules/react-dom && cd tests-ssr && yarn link:renex",
"publish:local": "yarn build && yarn link && yarn link --cwd node_modules/react && yarn link --cwd node_modules/react-dom && cd tests-ssr && yarn link:renex",
"unpublish:local": "cd tests-ssr && yarn unlink:renex && cd ../ && yarn unlink && yarn unlink --cwd node_modules/react && yarn unlink --cwd node_modules/react-dom"
},
"bugs": {
Expand Down
4 changes: 3 additions & 1 deletion src/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ type Props = CProps & { root?: string; children: ReactNode };

export default function Portal({ root = 'body', ...rest }: Props) {
const isBrowser = useIsBrowser();
return isBrowser ? createPortal(element(rest), document.querySelector(root) as HTMLElement) : null;
const portalEle = document.querySelector(root);

return isBrowser && portalEle ? createPortal(element(rest), portalEle) : null;
}
23 changes: 23 additions & 0 deletions src/StyleSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CProps } from '../types';
import { CSSProperties } from 'react';

type Key = keyof CSSProperties | (string & {});

type CSS = { [K in Key]?: string };

type Props = CProps & {
children: CSS;
};

const CSS = (
<StyleSheet>
{{
color: '',
'@media': '',
}}
</StyleSheet>
);

export default function StyleSheet(props: Props) {
return <div>Helloworld</div>;
}
7 changes: 5 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HTMLProps, ReactHTML } from 'react';

type StateConsumer<TState, TChild> = (state: TState, setState: (newState: TState | ((oldState: TState) => TState)) => void) => TChild;
export type StateConsumer<TState, TChild> = (
state: TState,
setState: (newState: TState | ((oldState: TState) => TState)) => void,
) => TChild;

type CProps = { as?: keyof ReactHTML } & Omit<HTMLProps<HTMLElement>, 'ref' | 'children'>;
export type CProps = { as?: keyof ReactHTML } & Omit<HTMLProps<HTMLElement>, 'ref' | 'children'>;

0 comments on commit 6028266

Please sign in to comment.