dev #1

Merged
Astrian merged 17 commits from dev into main 2025-02-20 04:29:20 +00:00
11 changed files with 113 additions and 45 deletions

View File

@ -4,6 +4,7 @@ on:
push: push:
branches: branches:
- main - main
- dev
jobs: jobs:
publish: publish:
@ -22,7 +23,24 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: npm install run: npm install
- name: Determine package name
id: package_name
run: |
if [ "${{ gitea.ref }}" == "refs/heads/main" ]; then
echo "PACKAGE_NAME=datenel-react" >> $GITEA_ENV
echo "ACCESS_LEVEL=public" >> $GITEA_ENV
elif [ "${{ gitea.ref }}" == "refs/heads/dev" ]; then
echo "PACKAGE_NAME=@astrian/datenel-react-dev" >> $GITEA_ENV
echo "ACCESS_LEVEL=restricted" >> $GITEA_ENV
fi
- name: Update package.json for dev releases
if: GITEA.ref == 'refs/heads/dev'
run: |
jq --arg name "@astrian/datenel-react-dev" '.name=$name' package.json > temp.json && mv temp.json package.json
jq --arg version "0.0.0-dev.$(date +%s)" '.version=$version' package.json > temp.json && mv temp.json package.json
- name: Publish to npm - name: Publish to npm
run: npm publish run: npm publish --access $ACCESS_LEVEL
env: env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

View File

@ -30,28 +30,27 @@ Here is an example of how to use Datenel in your React application:
```tsx ```tsx
import React from 'react' import React from 'react'
import { WeekPicker } from 'datenel-react' import { SingleDatePicker } from 'datenel-react'
import './app.scss'
export default () => { export default () => {
function onSelect(value) { function onSelect(value) {
alert(`You selected ${value.year}-${value-month}-${value.day}`) alert(`You selected ${value.year}-${value-month}-${value.day}`)
} }
return ( return (
<div className='app'> <div className='app'>
<div className="border"> <div className="border">
<WeekPicker <SingleDatePicker
value={{ value={{
year: 2025, year: 2025,
month: 1, month: 1,
day: 1 day: 1
}} }}
onSelect={onSelect} onSelect={onSelect}
/> />
</div> </div>
</div> </div>
) )
} }
``` ```
@ -64,6 +63,15 @@ export default () => {
More features are on the roadmap. More features are on the roadmap.
## Contribution & Development
```zsh
npm i # or `yarn`
npm run dev # or `yarn dev`
```
Then the package will launch a testing React hot-reload server on `localhost:1926`. The server file is available in the `playground` folder, feel free to modify the content inside it.
## License ## License
MIT MIT

11
package-lock.json generated
View File

@ -23,6 +23,7 @@
"typescript": "~5.7.2", "typescript": "~5.7.2",
"typescript-eslint": "^8.22.0", "typescript-eslint": "^8.22.0",
"vite": "^6.1.0", "vite": "^6.1.0",
"vite-plugin-css-injected-by-js": "^3.5.2",
"vite-plugin-dts": "^4.5.0" "vite-plugin-dts": "^4.5.0"
}, },
"peerDependencies": { "peerDependencies": {
@ -4523,6 +4524,16 @@
} }
} }
}, },
"node_modules/vite-plugin-css-injected-by-js": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/vite-plugin-css-injected-by-js/-/vite-plugin-css-injected-by-js-3.5.2.tgz",
"integrity": "sha512-2MpU/Y+SCZyWUB6ua3HbJCrgnF0KACAsmzOQt1UvRVJCGF6S8xdA3ZUhWcWdM9ivG4I5az8PnQmwwrkC2CAQrQ==",
"dev": true,
"license": "MIT",
"peerDependencies": {
"vite": ">2.0.0-0"
}
},
"node_modules/vite-plugin-dts": { "node_modules/vite-plugin-dts": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "https://registry.npmjs.org/vite-plugin-dts/-/vite-plugin-dts-4.5.0.tgz", "resolved": "https://registry.npmjs.org/vite-plugin-dts/-/vite-plugin-dts-4.5.0.tgz",

View File

@ -22,21 +22,25 @@
"eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.18", "eslint-plugin-react-refresh": "^0.4.18",
"globals": "^15.14.0", "globals": "^15.14.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"sass-embedded": "^1.85.0", "sass-embedded": "^1.85.0",
"typescript": "~5.7.2", "typescript": "~5.7.2",
"typescript-eslint": "^8.22.0", "typescript-eslint": "^8.22.0",
"vite": "^6.1.0", "vite": "^6.1.0",
"vite-plugin-dts": "^4.5.0", "vite-plugin-css-injected-by-js": "^3.5.2",
"react": "^19.0.0", "vite-plugin-dts": "^4.5.0"
"react-dom": "^19.0.0"
}, },
"exports": { "exports": {
"import": "./dist/datenel.es.js", "types": "./dist/src/index.d.ts",
"import": "./dist/index.es.js",
"require": "./dist/index.cjs.js", "require": "./dist/index.cjs.js",
"default": "./dist/datenel.es.js" "default": "./dist/index.es.js"
}, },
"main": "dist/index.cjs.js", "main": "dist/index.cjs.js",
"module": "dist/datenel.es.js", "module": "dist/index.es.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"files": ["dist"] "files": [
"dist"
]
} }

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import { WeekPicker } from "../src/index.ts" import { SingleDatePicker } from "../dist/index.es"
import './app.scss' import './app.scss'
export default () => { export default () => {
@ -11,7 +11,7 @@ export default () => {
return (<div className='app'> return (<div className='app'>
<div className="border"> <div className="border">
<WeekPicker <SingleDatePicker
value={{ value={{
year: 2025, year: 2025,
month: 1, month: 1,

View File

@ -1,7 +1,7 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { getCalendarDates, getL10Weekday, generateUniqueId, applyColor } from '../utils' import { getCalendarDates, getL10Weekday, generateUniqueId, applyColor } from '../utils'
interface Props { export interface SingleDatePickerProps {
/** /**
* Control the selected * Control the selected
* date programmatically, including situations like provide a default value or control the selected * date programmatically, including situations like provide a default value or control the selected
@ -78,9 +78,9 @@ interface Props {
* *
* @component * @component
* *
* @param {Props} props * @param {SingleDatePickerProps} props
*/ */
export default ({ value, onSelect, localization, onClose, mainColor = '#000000', accentColor = '#000000', reversedColor = '#ffffff', hoverColor = '#00000017', borderColor = '#e0e0e0' }: Props) => { const SingleDatePicker: React.FC = ({ value, onSelect, localization, onClose, mainColor = '#000000', accentColor = '#000000', reversedColor = '#ffffff', hoverColor = '#00000017', borderColor = '#e0e0e0' }: SingleDatePickerProps) => {
const [currentMonth, setCurrentMonth] = useState(new Date().getMonth()) const [currentMonth, setCurrentMonth] = useState(new Date().getMonth())
const [currentYear, setCurrentYear] = useState(new Date().getFullYear()) const [currentYear, setCurrentYear] = useState(new Date().getFullYear())
const [selectedDate, setSelectedDate] = useState(new Date()) const [selectedDate, setSelectedDate] = useState(new Date())
@ -225,3 +225,5 @@ export default ({ value, onSelect, localization, onClose, mainColor = '#000000',
</div> </div>
) )
} }
export default SingleDatePicker

View File

@ -1,3 +1,3 @@
import './style.scss' import './style.scss'
export {default as WeekPicker} from './components/SingleDatePicker.tsx' export {default as SingleDatePicker} from './components/SingleDatePicker'

View File

@ -10,9 +10,10 @@
/* Bundler mode */ /* Bundler mode */
"moduleResolution": "bundler", "moduleResolution": "bundler",
"allowImportingTsExtensions": true, "allowImportingTsExtensions": true,
"emitDeclarationOnly": true,
"declaration": true,
"isolatedModules": true, "isolatedModules": true,
"moduleDetection": "force", "moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx", "jsx": "react-jsx",
/* Linting */ /* Linting */
@ -20,7 +21,10 @@
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true "noUncheckedSideEffectImports": true,
"composite": true,
"outDir": "./dist" //
}, },
"include": ["src"] "include": ["src", "tsconfig.app.json", "tsconfig.node.json"]
} }

View File

@ -9,6 +9,9 @@
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"@/*": ["src/*"] "@/*": ["src/*"]
} },
} "declaration": true,
"outDir": "./dist"
},
"include": ["src/**/*", "tsconfig.app.json", "tsconfig.node.json"]
} }

View File

@ -9,16 +9,19 @@
/* Bundler mode */ /* Bundler mode */
"moduleResolution": "bundler", "moduleResolution": "bundler",
"allowImportingTsExtensions": true, "allowImportingTsExtensions": true,
"emitDeclarationOnly": true,
"declaration": true,
"isolatedModules": true, "isolatedModules": true,
"moduleDetection": "force", "moduleDetection": "force",
"noEmit": true,
/* Linting */ /* Linting */
"strict": true, "strict": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true "noUncheckedSideEffectImports": true,
"composite": true
}, },
"include": ["vite.config.ts"] "include": ["vite.config.ts"]
} }

View File

@ -2,24 +2,39 @@ import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts' import dts from 'vite-plugin-dts'
import path from "path" import path from "path"
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js"
export default defineConfig(({mode}) => ({ export default defineConfig(({mode}) => ({
build: { build: {
lib: { lib: {
entry: "src/index.ts", entry: "src/index.ts",
name: "datenel-react", name: "datenel-react",
fileName: format => `datenel.${format}.js`, fileName: format => `index.${format}.js`,
}, },
rollupOptions: { rollupOptions: {
preserveEntrySignatures: "strict",
external: ["react"], external: ["react"],
output: { output: {
globals: { globals: {
react: "React", react: "React",
"react-dom": "ReactDOM",
}, },
assetFileNames: assetInfo => {
if (assetInfo.names[0].endsWith(".css")) {
return "index.css";
}
return `assets/${assetInfo.names[0]}`;
}
}, },
}, },
}, },
plugins: [react(), dts()], plugins: [
react(),
dts({
tsconfigPath: "./tsconfig.app.json"
}),
cssInjectedByJsPlugin()
],
resolve: { resolve: {
alias: { alias: {
"@": path.resolve(__dirname, "./src"), "@": path.resolve(__dirname, "./src"),