Skip to content

Commit

Permalink
🦊 compile with microbundle
Browse files Browse the repository at this point in the history
  • Loading branch information
hxf31891 committed Nov 28, 2023
1 parent 95c78e5 commit 301adde
Show file tree
Hide file tree
Showing 8 changed files with 3,452 additions and 360 deletions.
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

34 changes: 29 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
{
"name": "react-best-gradient-color-picker",
"version": "2.3.2",
"version": "2.3.3",
"description": "An easy to use color/gradient picker for React.js",
"source": "src/index.js",
"main": "lib/index.js",
"module": "lib/index.module.js",
"esmodule": "lib/index.esmodule.js",
"umd:main": "lib/index.umd.js",
"types": "lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"umd": "./lib/index.umd.js",
"import": "./lib/index.module.js",
"require": "./lib/index.js",
"default": "./lib/index.module.js"
}
},
"scripts": {
"prepare": "babel src --out-dir lib --copy-files",
"test": "jest",
"eslint": "npx eslint . --ext .js,.jsx,.ts,.tsx",
"eslint:fix": "npx eslint . --ext .js,.jsx,.ts,.tsx --fix"
"build": "del-cli 'lib/*' && microbundle --entry src/index.js --jsx React.createElement --jsxFragment React.Fragment --name react-best-gradient-color-picker --tsconfig tsconfig.build.json",
"prepublishOnly": "npm run build",
"check-release": "npm publish --dry-run",
"release": "npm publish"
},
"files": [
"lib/*.{js,mjs,ts,map}",
"lib/components/*.ts",
"LICENSE",
"README.md",
"package.json"
],
"repository": {
"type": "git",
"url": "git+https://github.com/hxf31891/react-gradient-color-picker.git"
Expand Down Expand Up @@ -36,6 +57,8 @@
"@babel/preset-env": "^7.18.10",
"@babel/preset-react": "^7.16.7",
"@types/jest": "^29.0.0",
"cpy-cli": "^3.1.1",
"del-cli": "^3.0.1",
"eslint": "8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-react-app": "^7.0.1",
Expand All @@ -44,6 +67,7 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-react": "^7.31.8",
"microbundle": "0.13.0",
"ts-jest": "^28.0.8"
},
"license": "MIT",
Expand Down
77 changes: 77 additions & 0 deletions src/components/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { useRef, useState, useEffect } from 'react'
import PickerContextWrapper from '../context'
import Picker from './Picker'
import { defaultLocales } from '../constants'
import { objectToString } from '../utils/utils'

export function ColorPicker({
value = 'rgba(175, 51, 242, 1)',
onChange = () => {},
hideControls = false,
hideInputs = false,
hideOpacity = false,
hidePresets = false,
hideHue = false,
presets = [],
hideEyeDrop = false,
hideAdvancedSliders = false,
hideColorGuide = false,
hideInputType = false,
hideColorTypeBtns = false,
hideGradientType = false,
hideGradientAngle = false,
hideGradientStop = false,
hideGradientControls = false,
locales = defaultLocales,
width = 294,
height = 294,
style = {},
className,
}) {
const contRef = useRef(null)
const [bounds, setBounds] = useState({});
const safeValue = objectToString(value);

document
.getElementsByTagName("head")[0]
.insertAdjacentHTML(
"beforeend",
'<link rel="stylesheet" href="https://prod-api.outsyde.app/packagestyles.css" />'
);

useEffect(() => {
setBounds(contRef?.current?.getBoundingClientRect())
}, [])

return (
<div ref={contRef} style={{ ...style, width: width }} className={className}>
<PickerContextWrapper
bounds={bounds}
value={safeValue}
onChange={onChange}
squareSize={width}
squareHeight={height}
hideOpacity={hideOpacity}
>
<Picker
hideControls={hideControls}
hideInputs={hideInputs}
hidePresets={hidePresets}
hideOpacity={hideOpacity}
hideHue={hideHue}
presets={presets}
hideEyeDrop={hideEyeDrop}
hideAdvancedSliders={hideAdvancedSliders}
hideColorGuide={hideColorGuide}
hideInputType={hideInputType}
hideColorTypeBtns={hideColorTypeBtns}
hideGradientType={hideGradientType}
hideGradientAngle={hideGradientAngle}
hideGradientStop={hideGradientStop}
hideGradientControls={hideGradientControls}
locales={locales}
/>
</PickerContextWrapper>
</div>
)
}
78 changes: 3 additions & 75 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,3 @@
import React, { useRef, useState, useEffect } from 'react'
import PickerContextWrapper from './context'
import Picker from './components/Picker'
import { defaultLocales } from './constants'
import { objectToString } from './utils/utils'
import "./styles.css";

export * from './hooks/useColorPicker'

function ColorPicker({
value = 'rgba(175, 51, 242, 1)',
onChange = () => {},
hideControls = false,
hideInputs = false,
hideOpacity = false,
hidePresets = false,
hideHue = false,
presets = [],
hideEyeDrop = false,
hideAdvancedSliders = false,
hideColorGuide = false,
hideInputType = false,
hideColorTypeBtns = false,
hideGradientType = false,
hideGradientAngle = false,
hideGradientStop = false,
hideGradientControls = false,
locales = defaultLocales,
width = 294,
height = 294,
style = {},
className,
}) {
const contRef = useRef(null)
const [bounds, setBounds] = useState({});
const safeValue = objectToString(value);

useEffect(() => {
setBounds(contRef?.current?.getBoundingClientRect())
}, [])

return (
<div ref={contRef} style={{ ...style, width: width }} className={className}>
<PickerContextWrapper
bounds={bounds}
value={safeValue}
onChange={onChange}
squareSize={width}
squareHeight={height}
hideOpacity={hideOpacity}
>
<Picker
hideControls={hideControls}
hideInputs={hideInputs}
hidePresets={hidePresets}
hideOpacity={hideOpacity}
hideHue={hideHue}
presets={presets}
hideEyeDrop={hideEyeDrop}
hideAdvancedSliders={hideAdvancedSliders}
hideColorGuide={hideColorGuide}
hideInputType={hideInputType}
hideColorTypeBtns={hideColorTypeBtns}
hideGradientType={hideGradientType}
hideGradientAngle={hideGradientAngle}
hideGradientStop={hideGradientStop}
hideGradientControls={hideGradientControls}
locales={locales}
/>
</PickerContextWrapper>
</div>
)
}

export default ColorPicker
import { ColorPicker } from './components';
export { useColorPicker } from './hooks/useColorPicker';
export default ColorPicker;
Loading

0 comments on commit 301adde

Please sign in to comment.