@sunggang/ui-lib 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
- import React, { useMemo, useRef, useReducer, useEffect, useCallback, forwardRef, useImperativeHandle, Fragment, useState } from 'react';
2
+ import * as React from 'react';
3
+ import React__default, { useMemo, useRef, useReducer, useEffect, useCallback, forwardRef, useImperativeHandle, Fragment, useState } from 'react';
4
+ import * as SwitchPrimitives from '@radix-ui/react-switch';
5
+ import { clsx } from 'clsx';
6
+ import { twMerge } from 'tailwind-merge';
3
7
 
4
8
  var styles = {};
5
9
 
@@ -1929,7 +1933,7 @@ function _iterableToArray$1(iter) {
1929
1933
  function _arrayWithoutHoles$1(arr) {
1930
1934
  if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
1931
1935
  }
1932
- function ownKeys$3(object, enumerableOnly) {
1936
+ function ownKeys$4(object, enumerableOnly) {
1933
1937
  var keys = Object.keys(object);
1934
1938
  if (Object.getOwnPropertySymbols) {
1935
1939
  var symbols = Object.getOwnPropertySymbols(object);
@@ -1942,9 +1946,9 @@ function ownKeys$3(object, enumerableOnly) {
1942
1946
  function _objectSpread$1(target) {
1943
1947
  for(var i = 1; i < arguments.length; i++){
1944
1948
  var source = null != arguments[i] ? arguments[i] : {};
1945
- i % 2 ? ownKeys$3(Object(source), !0).forEach(function(key) {
1949
+ i % 2 ? ownKeys$4(Object(source), !0).forEach(function(key) {
1946
1950
  _defineProperty$1(target, key, source[key]);
1947
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function(key) {
1951
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function(key) {
1948
1952
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1949
1953
  });
1950
1954
  }
@@ -2338,7 +2342,7 @@ function _iterableToArrayLimit(arr, i) {
2338
2342
  function _arrayWithHoles(arr) {
2339
2343
  if (Array.isArray(arr)) return arr;
2340
2344
  }
2341
- function ownKeys$2(object, enumerableOnly) {
2345
+ function ownKeys$3(object, enumerableOnly) {
2342
2346
  var keys = Object.keys(object);
2343
2347
  if (Object.getOwnPropertySymbols) {
2344
2348
  var symbols = Object.getOwnPropertySymbols(object);
@@ -2351,9 +2355,9 @@ function ownKeys$2(object, enumerableOnly) {
2351
2355
  function _objectSpread(target) {
2352
2356
  for(var i = 1; i < arguments.length; i++){
2353
2357
  var source = null != arguments[i] ? arguments[i] : {};
2354
- i % 2 ? ownKeys$2(Object(source), !0).forEach(function(key) {
2358
+ i % 2 ? ownKeys$3(Object(source), !0).forEach(function(key) {
2355
2359
  _defineProperty(target, key, source[key]);
2356
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function(key) {
2360
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function(key) {
2357
2361
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2358
2362
  });
2359
2363
  }
@@ -2422,7 +2426,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
2422
2426
  }, [
2423
2427
  open
2424
2428
  ]); // TODO: Figure out why react-styleguidist cannot create docs if we don't return a jsx element
2425
- return /*#__PURE__*/ React.createElement(Fragment, null, children(_objectSpread(_objectSpread({}, props), {}, {
2429
+ return /*#__PURE__*/ React__default.createElement(Fragment, null, children(_objectSpread(_objectSpread({}, props), {}, {
2426
2430
  open: open
2427
2431
  })));
2428
2432
  });
@@ -3290,188 +3294,6 @@ function v4(options, buf, offset) {
3290
3294
  return stringify(rnds);
3291
3295
  }
3292
3296
 
3293
- function _array_like_to_array$2(arr, len) {
3294
- if (len == null || len > arr.length) len = arr.length;
3295
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
3296
- return arr2;
3297
- }
3298
- function _array_with_holes$2(arr) {
3299
- if (Array.isArray(arr)) return arr;
3300
- }
3301
- function _define_property$1(obj, key, value) {
3302
- if (key in obj) {
3303
- Object.defineProperty(obj, key, {
3304
- value: value,
3305
- enumerable: true,
3306
- configurable: true,
3307
- writable: true
3308
- });
3309
- } else {
3310
- obj[key] = value;
3311
- }
3312
- return obj;
3313
- }
3314
- function _iterable_to_array_limit$2(arr, i) {
3315
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
3316
- if (_i == null) return;
3317
- var _arr = [];
3318
- var _n = true;
3319
- var _d = false;
3320
- var _s, _e;
3321
- try {
3322
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
3323
- _arr.push(_s.value);
3324
- if (i && _arr.length === i) break;
3325
- }
3326
- } catch (err) {
3327
- _d = true;
3328
- _e = err;
3329
- } finally{
3330
- try {
3331
- if (!_n && _i["return"] != null) _i["return"]();
3332
- } finally{
3333
- if (_d) throw _e;
3334
- }
3335
- }
3336
- return _arr;
3337
- }
3338
- function _non_iterable_rest$2() {
3339
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3340
- }
3341
- function _object_spread$1(target) {
3342
- for(var i = 1; i < arguments.length; i++){
3343
- var source = arguments[i] != null ? arguments[i] : {};
3344
- var ownKeys = Object.keys(source);
3345
- if (typeof Object.getOwnPropertySymbols === "function") {
3346
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
3347
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
3348
- }));
3349
- }
3350
- ownKeys.forEach(function(key) {
3351
- _define_property$1(target, key, source[key]);
3352
- });
3353
- }
3354
- return target;
3355
- }
3356
- function ownKeys$1(object, enumerableOnly) {
3357
- var keys = Object.keys(object);
3358
- if (Object.getOwnPropertySymbols) {
3359
- var symbols = Object.getOwnPropertySymbols(object);
3360
- if (enumerableOnly) {
3361
- symbols = symbols.filter(function(sym) {
3362
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
3363
- });
3364
- }
3365
- keys.push.apply(keys, symbols);
3366
- }
3367
- return keys;
3368
- }
3369
- function _object_spread_props$1(target, source) {
3370
- source = source != null ? source : {};
3371
- if (Object.getOwnPropertyDescriptors) {
3372
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
3373
- } else {
3374
- ownKeys$1(Object(source)).forEach(function(key) {
3375
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
3376
- });
3377
- }
3378
- return target;
3379
- }
3380
- function _sliced_to_array$2(arr, i) {
3381
- return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$2();
3382
- }
3383
- function _unsupported_iterable_to_array$2(o, minLen) {
3384
- if (!o) return;
3385
- if (typeof o === "string") return _array_like_to_array$2(o, minLen);
3386
- var n = Object.prototype.toString.call(o).slice(8, -1);
3387
- if (n === "Object" && o.constructor) n = o.constructor.name;
3388
- if (n === "Map" || n === "Set") return Array.from(n);
3389
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
3390
- }
3391
- var DropImage = function(param) {
3392
- var _param_preview = param.preview, preview = _param_preview === void 0 ? true : _param_preview, setFiles = param.setFiles, imageUrls = param.imageUrls;
3393
- var _useState = _sliced_to_array$2(useState([]), 2), previewFiles = _useState[0], setPreviewFiles = _useState[1];
3394
- var _useDropzone = useDropzone({
3395
- accept: {
3396
- "image/png": [
3397
- ".png"
3398
- ],
3399
- "image/jpeg": [
3400
- ".jpg",
3401
- ".jpeg"
3402
- ]
3403
- },
3404
- maxFiles: 10,
3405
- maxSize: 5000000,
3406
- onDrop: function(dropFiles) {
3407
- var newFiles = [];
3408
- setFiles(dropFiles);
3409
- dropFiles.forEach(function(dropFile) {
3410
- Object.assign(dropFile, {
3411
- preview: URL.createObjectURL(dropFile),
3412
- uuid: v4()
3413
- });
3414
- newFiles.push(dropFile);
3415
- setPreviewFiles(newFiles);
3416
- });
3417
- }
3418
- }), getRootProps = _useDropzone.getRootProps, getInputProps = _useDropzone.getInputProps; _useDropzone.isDragActive; _useDropzone.isDragAccept; _useDropzone.isDragReject;
3419
- return /*#__PURE__*/ jsxs("section", {
3420
- className: "w-full",
3421
- children: [
3422
- /*#__PURE__*/ jsxs("div", _object_spread_props$1(_object_spread$1({}, getRootProps({
3423
- className: "dropzone"
3424
- })), {
3425
- children: [
3426
- /*#__PURE__*/ jsx("input", _object_spread$1({}, getInputProps())),
3427
- /*#__PURE__*/ jsx("div", {
3428
- className: "flex justify-between",
3429
- children: /*#__PURE__*/ jsx("div", {
3430
- className: "w-full bg-gray-light rounded-lg",
3431
- children: /*#__PURE__*/ jsx("div", {
3432
- className: "border-2 border-dashed border-gray-400 rounded-lg bg-gray-100",
3433
- children: /*#__PURE__*/ jsxs("div", {
3434
- className: "flex items-center flex-col h-48 justify-center",
3435
- children: [
3436
- /*#__PURE__*/ jsx("p", {
3437
- className: "font-normal text-sm text-gray-400 py-4",
3438
- children: "圖片僅支援 png、jpg、jpeg"
3439
- }),
3440
- /*#__PURE__*/ jsx("h5", {
3441
- className: "mb-2 text-xl font-bold tracking-tight text-gray-700",
3442
- children: "拖曳圖片至此"
3443
- })
3444
- ]
3445
- })
3446
- })
3447
- })
3448
- })
3449
- ]
3450
- })),
3451
- preview && /*#__PURE__*/ jsx("div", {
3452
- className: "flex pt-2 gap-2",
3453
- children: (previewFiles === null || previewFiles === void 0 ? void 0 : previewFiles.length) ? previewFiles.length > 0 ? previewFiles.map(function(item) {
3454
- return /*#__PURE__*/ jsx("div", {
3455
- children: /*#__PURE__*/ jsx("img", {
3456
- className: "w-24 h-24 object-cover",
3457
- src: item === null || item === void 0 ? void 0 : item.preview,
3458
- alt: ""
3459
- })
3460
- }, item === null || item === void 0 ? void 0 : item.uuid);
3461
- }) : null : imageUrls && imageUrls.length ? imageUrls.map(function(item) {
3462
- return /*#__PURE__*/ jsx("div", {
3463
- children: /*#__PURE__*/ jsx("img", {
3464
- className: "w-24 h-24 object-cover",
3465
- src: item === null || item === void 0 ? void 0 : item.url,
3466
- alt: ""
3467
- })
3468
- }, item === null || item === void 0 ? void 0 : item.url);
3469
- }) : null
3470
- })
3471
- ]
3472
- });
3473
- };
3474
-
3475
3297
  function _assert_this_initialized(self) {
3476
3298
  if (self === void 0) {
3477
3299
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -3497,7 +3319,7 @@ function _create_class(Constructor, protoProps, staticProps) {
3497
3319
  if (staticProps) _defineProperties(Constructor, staticProps);
3498
3320
  return Constructor;
3499
3321
  }
3500
- function _define_property(obj, key, value) {
3322
+ function _define_property$2(obj, key, value) {
3501
3323
  if (key in obj) {
3502
3324
  Object.defineProperty(obj, key, {
3503
3325
  value: value,
@@ -3536,7 +3358,7 @@ function _instanceof(left, right) {
3536
3358
  return left instanceof right;
3537
3359
  }
3538
3360
  }
3539
- function _object_spread(target) {
3361
+ function _object_spread$2(target) {
3540
3362
  for(var i = 1; i < arguments.length; i++){
3541
3363
  var source = arguments[i] != null ? arguments[i] : {};
3542
3364
  var ownKeys = Object.keys(source);
@@ -3546,12 +3368,12 @@ function _object_spread(target) {
3546
3368
  }));
3547
3369
  }
3548
3370
  ownKeys.forEach(function(key) {
3549
- _define_property(target, key, source[key]);
3371
+ _define_property$2(target, key, source[key]);
3550
3372
  });
3551
3373
  }
3552
3374
  return target;
3553
3375
  }
3554
- function ownKeys(object, enumerableOnly) {
3376
+ function ownKeys$2(object, enumerableOnly) {
3555
3377
  var keys = Object.keys(object);
3556
3378
  if (Object.getOwnPropertySymbols) {
3557
3379
  var symbols = Object.getOwnPropertySymbols(object);
@@ -3564,12 +3386,12 @@ function ownKeys(object, enumerableOnly) {
3564
3386
  }
3565
3387
  return keys;
3566
3388
  }
3567
- function _object_spread_props(target, source) {
3389
+ function _object_spread_props$2(target, source) {
3568
3390
  source = source != null ? source : {};
3569
3391
  if (Object.getOwnPropertyDescriptors) {
3570
3392
  Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
3571
3393
  } else {
3572
- ownKeys(Object(source)).forEach(function(key) {
3394
+ ownKeys$2(Object(source)).forEach(function(key) {
3573
3395
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
3574
3396
  });
3575
3397
  }
@@ -3677,8 +3499,8 @@ var defaultIconTransformations = Object.freeze({
3677
3499
  vFlip: false,
3678
3500
  hFlip: false
3679
3501
  });
3680
- var defaultIconProps = Object.freeze(_object_spread({}, defaultIconDimensions, defaultIconTransformations));
3681
- var defaultExtendedIconProps = Object.freeze(_object_spread_props(_object_spread({}, defaultIconProps), {
3502
+ var defaultIconProps = Object.freeze(_object_spread$2({}, defaultIconDimensions, defaultIconTransformations));
3503
+ var defaultExtendedIconProps = Object.freeze(_object_spread_props$2(_object_spread$2({}, defaultIconProps), {
3682
3504
  body: "",
3683
3505
  hidden: false
3684
3506
  }));
@@ -3766,7 +3588,7 @@ function parseIconSet(data, callback) {
3766
3588
  }
3767
3589
  return names;
3768
3590
  }
3769
- var optionalPropertyDefaults = _object_spread({
3591
+ var optionalPropertyDefaults = _object_spread$2({
3770
3592
  provider: "",
3771
3593
  aliases: {},
3772
3594
  not_found: {}
@@ -3835,7 +3657,7 @@ function addIconSet(storage, data) {
3835
3657
  function addIconToStorage(storage, name, icon) {
3836
3658
  try {
3837
3659
  if (typeof icon.body === "string") {
3838
- storage.icons[name] = _object_spread({}, icon);
3660
+ storage.icons[name] = _object_spread$2({}, icon);
3839
3661
  return true;
3840
3662
  }
3841
3663
  } catch (err) {}
@@ -3898,7 +3720,7 @@ var defaultIconSizeCustomisations = Object.freeze({
3898
3720
  width: null,
3899
3721
  height: null
3900
3722
  });
3901
- var defaultIconCustomisations = Object.freeze(_object_spread({}, defaultIconSizeCustomisations, defaultIconTransformations));
3723
+ var defaultIconCustomisations = Object.freeze(_object_spread$2({}, defaultIconSizeCustomisations, defaultIconTransformations));
3902
3724
  var unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
3903
3725
  var unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
3904
3726
  function calculateSize(size, ratio, precision) {
@@ -3941,8 +3763,8 @@ var isUnsetKeyword = function(value) {
3941
3763
  return value === "unset" || value === "undefined" || value === "none";
3942
3764
  };
3943
3765
  function iconToSVG(icon, customisations) {
3944
- var fullIcon = _object_spread({}, defaultIconProps, icon);
3945
- var fullCustomisations = _object_spread({}, defaultIconCustomisations, customisations);
3766
+ var fullIcon = _object_spread$2({}, defaultIconProps, icon);
3767
+ var fullCustomisations = _object_spread$2({}, defaultIconCustomisations, customisations);
3946
3768
  var box = {
3947
3769
  left: fullIcon.left,
3948
3770
  top: fullIcon.top,
@@ -4564,7 +4386,7 @@ function sendQuery(config, payload, query, done) {
4564
4386
  }
4565
4387
  // src/index.ts
4566
4388
  function initRedundancy(cfg) {
4567
- var config = _object_spread({}, defaultConfig, cfg);
4389
+ var config = _object_spread$2({}, defaultConfig, cfg);
4568
4390
  var queries = [];
4569
4391
  function cleanup() {
4570
4392
  queries = queries.filter(function(item) {
@@ -4926,7 +4748,7 @@ var loadIcons = function(icons, callback) {
4926
4748
  return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback;
4927
4749
  };
4928
4750
  function mergeCustomisations(defaults, item) {
4929
- var result = _object_spread({}, defaults);
4751
+ var result = _object_spread$2({}, defaults);
4930
4752
  for(var key in item){
4931
4753
  var value = item[key];
4932
4754
  var valueType = typeof value === "undefined" ? "undefined" : _type_of(value);
@@ -5021,7 +4843,7 @@ function cleanUpInnerHTML(html) {
5021
4843
  }
5022
4844
  return policy ? policy.createHTML(html) : html;
5023
4845
  }
5024
- var defaultExtendedIconCustomisations = _object_spread_props(_object_spread({}, defaultIconCustomisations), {
4846
+ var defaultExtendedIconCustomisations = _object_spread_props$2(_object_spread$2({}, defaultIconCustomisations), {
5025
4847
  inline: false
5026
4848
  });
5027
4849
  /**
@@ -5062,7 +4884,7 @@ for(var prefix in propsToAddTo){
5062
4884
  }
5063
4885
  /**
5064
4886
  * Default values for customisations for inline icon
5065
- */ var inlineDefaults = _object_spread_props(_object_spread({}, defaultExtendedIconCustomisations), {
4887
+ */ var inlineDefaults = _object_spread_props$2(_object_spread$2({}, defaultExtendedIconCustomisations), {
5066
4888
  inline: true
5067
4889
  });
5068
4890
  /**
@@ -5087,7 +4909,7 @@ ref) {
5087
4909
  var style = {};
5088
4910
  var customStyle = props.style || {};
5089
4911
  // Create SVG component properties
5090
- var componentProps = _object_spread_props(_object_spread({}, mode === "svg" ? svgDefaults : {}), {
4912
+ var componentProps = _object_spread_props$2(_object_spread$2({}, mode === "svg" ? svgDefaults : {}), {
5091
4913
  ref: ref
5092
4914
  });
5093
4915
  // Get element properties
@@ -5153,7 +4975,7 @@ ref) {
5153
4975
  }
5154
4976
  if (mode === "svg") {
5155
4977
  // Add style
5156
- componentProps.style = _object_spread({}, style, customStyle);
4978
+ componentProps.style = _object_spread$2({}, style, customStyle);
5157
4979
  // Add icon stuff
5158
4980
  Object.assign(componentProps, renderAttribs);
5159
4981
  // Counter for ids based on "id" property to render icons consistently on server and client
@@ -5169,23 +4991,23 @@ ref) {
5169
4991
  return id + "ID" + localCounter++;
5170
4992
  } : "iconifyReact"))
5171
4993
  };
5172
- return React.createElement("svg", componentProps);
4994
+ return React__default.createElement("svg", componentProps);
5173
4995
  }
5174
4996
  // Render <span> with style
5175
4997
  var body = icon.body, width = icon.width, height = icon.height;
5176
4998
  var useMask = mode === "mask" || (mode === "bg" ? false : body.indexOf("currentColor") !== -1);
5177
4999
  // Generate SVG
5178
- var html = iconToHTML(body, _object_spread_props(_object_spread({}, renderAttribs), {
5000
+ var html = iconToHTML(body, _object_spread_props$2(_object_spread$2({}, renderAttribs), {
5179
5001
  width: width + "",
5180
5002
  height: height + ""
5181
5003
  }));
5182
5004
  // Generate style
5183
- componentProps.style = _object_spread(_object_spread_props(_object_spread({}, style), {
5005
+ componentProps.style = _object_spread$2(_object_spread_props$2(_object_spread$2({}, style), {
5184
5006
  "--svg": svgToURL(html),
5185
5007
  "width": fixSize(renderAttribs.width),
5186
5008
  "height": fixSize(renderAttribs.height)
5187
5009
  }), commonProps, useMask ? monotoneProps : coloredProps, customStyle);
5188
- return React.createElement("span", componentProps);
5010
+ return React__default.createElement("span", componentProps);
5189
5011
  };
5190
5012
  /**
5191
5013
  * Initialise stuff
@@ -5387,45 +5209,237 @@ var IconComponent = /*#__PURE__*/ function(_React_Component) {
5387
5209
  var icon = this.state.icon;
5388
5210
  if (icon === null) {
5389
5211
  // Render placeholder
5390
- return props.children ? props.children : React.createElement("span", {});
5212
+ return props.children ? props.children : React__default.createElement("span", {});
5391
5213
  }
5392
5214
  // Add classes
5393
5215
  var newProps = props;
5394
5216
  if (icon.classes) {
5395
- newProps = _object_spread_props(_object_spread({}, props), {
5217
+ newProps = _object_spread_props$2(_object_spread$2({}, props), {
5396
5218
  className: (typeof props.className === "string" ? props.className + " " : "") + icon.classes.join(" ")
5397
5219
  });
5398
5220
  }
5399
5221
  // Render icon
5400
- return render(_object_spread({}, defaultIconProps, icon.data), newProps, props._inline, props._ref);
5222
+ return render(_object_spread$2({}, defaultIconProps, icon.data), newProps, props._inline, props._ref);
5401
5223
  }
5402
5224
  }
5403
5225
  ]);
5404
5226
  return IconComponent;
5405
- }(React.Component);
5227
+ }(React__default.Component);
5406
5228
  /**
5407
5229
  * Block icon
5408
5230
  *
5409
5231
  * @param props - Component properties
5410
- */ var Icon = React.forwardRef(function Icon(props, ref) {
5411
- var newProps = _object_spread_props(_object_spread({}, props), {
5232
+ */ var Icon = React__default.forwardRef(function Icon(props, ref) {
5233
+ var newProps = _object_spread_props$2(_object_spread$2({}, props), {
5412
5234
  _ref: ref,
5413
5235
  _inline: false
5414
5236
  });
5415
- return React.createElement(IconComponent, newProps);
5237
+ return React__default.createElement(IconComponent, newProps);
5416
5238
  });
5417
5239
  /**
5418
5240
  * Inline icon (has negative verticalAlign that makes it behave like icon font)
5419
5241
  *
5420
5242
  * @param props - Component properties
5421
- */ React.forwardRef(function InlineIcon(props, ref) {
5422
- var newProps = _object_spread_props(_object_spread({}, props), {
5243
+ */ React__default.forwardRef(function InlineIcon(props, ref) {
5244
+ var newProps = _object_spread_props$2(_object_spread$2({}, props), {
5423
5245
  _ref: ref,
5424
5246
  _inline: true
5425
5247
  });
5426
- return React.createElement(IconComponent, newProps);
5248
+ return React__default.createElement(IconComponent, newProps);
5427
5249
  });
5428
5250
 
5251
+ function _array_like_to_array$2(arr, len) {
5252
+ if (len == null || len > arr.length) len = arr.length;
5253
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5254
+ return arr2;
5255
+ }
5256
+ function _array_with_holes$2(arr) {
5257
+ if (Array.isArray(arr)) return arr;
5258
+ }
5259
+ function _define_property$1(obj, key, value) {
5260
+ if (key in obj) {
5261
+ Object.defineProperty(obj, key, {
5262
+ value: value,
5263
+ enumerable: true,
5264
+ configurable: true,
5265
+ writable: true
5266
+ });
5267
+ } else {
5268
+ obj[key] = value;
5269
+ }
5270
+ return obj;
5271
+ }
5272
+ function _iterable_to_array_limit$2(arr, i) {
5273
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
5274
+ if (_i == null) return;
5275
+ var _arr = [];
5276
+ var _n = true;
5277
+ var _d = false;
5278
+ var _s, _e;
5279
+ try {
5280
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
5281
+ _arr.push(_s.value);
5282
+ if (i && _arr.length === i) break;
5283
+ }
5284
+ } catch (err) {
5285
+ _d = true;
5286
+ _e = err;
5287
+ } finally{
5288
+ try {
5289
+ if (!_n && _i["return"] != null) _i["return"]();
5290
+ } finally{
5291
+ if (_d) throw _e;
5292
+ }
5293
+ }
5294
+ return _arr;
5295
+ }
5296
+ function _non_iterable_rest$2() {
5297
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5298
+ }
5299
+ function _object_spread$1(target) {
5300
+ for(var i = 1; i < arguments.length; i++){
5301
+ var source = arguments[i] != null ? arguments[i] : {};
5302
+ var ownKeys = Object.keys(source);
5303
+ if (typeof Object.getOwnPropertySymbols === "function") {
5304
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
5305
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
5306
+ }));
5307
+ }
5308
+ ownKeys.forEach(function(key) {
5309
+ _define_property$1(target, key, source[key]);
5310
+ });
5311
+ }
5312
+ return target;
5313
+ }
5314
+ function ownKeys$1(object, enumerableOnly) {
5315
+ var keys = Object.keys(object);
5316
+ if (Object.getOwnPropertySymbols) {
5317
+ var symbols = Object.getOwnPropertySymbols(object);
5318
+ if (enumerableOnly) {
5319
+ symbols = symbols.filter(function(sym) {
5320
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
5321
+ });
5322
+ }
5323
+ keys.push.apply(keys, symbols);
5324
+ }
5325
+ return keys;
5326
+ }
5327
+ function _object_spread_props$1(target, source) {
5328
+ source = source != null ? source : {};
5329
+ if (Object.getOwnPropertyDescriptors) {
5330
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
5331
+ } else {
5332
+ ownKeys$1(Object(source)).forEach(function(key) {
5333
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
5334
+ });
5335
+ }
5336
+ return target;
5337
+ }
5338
+ function _sliced_to_array$2(arr, i) {
5339
+ return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$2();
5340
+ }
5341
+ function _unsupported_iterable_to_array$2(o, minLen) {
5342
+ if (!o) return;
5343
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
5344
+ var n = Object.prototype.toString.call(o).slice(8, -1);
5345
+ if (n === "Object" && o.constructor) n = o.constructor.name;
5346
+ if (n === "Map" || n === "Set") return Array.from(n);
5347
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
5348
+ }
5349
+ var DropImage = function(param) {
5350
+ var _param_preview = param.preview, preview = _param_preview === void 0 ? true : _param_preview, setFiles = param.setFiles, imageUrls = param.imageUrls;
5351
+ var _useState = _sliced_to_array$2(useState([]), 2), previewFiles = _useState[0], setPreviewFiles = _useState[1];
5352
+ var _useDropzone = useDropzone({
5353
+ accept: {
5354
+ "image/png": [
5355
+ ".png"
5356
+ ],
5357
+ "image/jpeg": [
5358
+ ".jpg",
5359
+ ".jpeg"
5360
+ ]
5361
+ },
5362
+ maxFiles: 10,
5363
+ maxSize: 5000000,
5364
+ onDrop: function(dropFiles) {
5365
+ var newFiles = [];
5366
+ setFiles(dropFiles);
5367
+ dropFiles.forEach(function(dropFile) {
5368
+ Object.assign(dropFile, {
5369
+ preview: URL.createObjectURL(dropFile),
5370
+ uuid: v4()
5371
+ });
5372
+ newFiles.push(dropFile);
5373
+ setPreviewFiles(newFiles);
5374
+ });
5375
+ }
5376
+ }), getRootProps = _useDropzone.getRootProps, getInputProps = _useDropzone.getInputProps; _useDropzone.isDragActive; _useDropzone.isDragAccept; _useDropzone.isDragReject;
5377
+ return /*#__PURE__*/ jsxs("section", {
5378
+ className: "w-full",
5379
+ children: [
5380
+ /*#__PURE__*/ jsxs("div", _object_spread_props$1(_object_spread$1({}, getRootProps({
5381
+ className: "dropzone"
5382
+ })), {
5383
+ children: [
5384
+ /*#__PURE__*/ jsx("input", _object_spread$1({}, getInputProps())),
5385
+ /*#__PURE__*/ jsx("div", {
5386
+ className: "flex justify-between",
5387
+ children: /*#__PURE__*/ jsx("div", {
5388
+ className: "w-full bg-gray-light rounded-lg",
5389
+ children: /*#__PURE__*/ jsxs("div", {
5390
+ className: "border-2 border-dashed border-gray-400 rounded-lg bg-gray-100",
5391
+ children: [
5392
+ /*#__PURE__*/ jsx("div", {
5393
+ className: "flex justify-center py-8",
5394
+ children: /*#__PURE__*/ jsx(Icon, {
5395
+ icon: "material-symbols:upload",
5396
+ width: "2.5rem",
5397
+ height: "2.5rem"
5398
+ })
5399
+ }),
5400
+ /*#__PURE__*/ jsxs("div", {
5401
+ className: "flex items-center flex-col justify-center",
5402
+ children: [
5403
+ /*#__PURE__*/ jsx("p", {
5404
+ className: "font-normal text-sm text-gray-400 pb-4",
5405
+ children: "圖片僅支援 png、jpg、jpeg"
5406
+ }),
5407
+ /*#__PURE__*/ jsx("h5", {
5408
+ className: "mb-2 text-xl font-bold tracking-tight text-gray-700 pb-4",
5409
+ children: "拖曳圖片至此"
5410
+ })
5411
+ ]
5412
+ })
5413
+ ]
5414
+ })
5415
+ })
5416
+ })
5417
+ ]
5418
+ })),
5419
+ preview && /*#__PURE__*/ jsx("div", {
5420
+ className: "flex pt-2 gap-2",
5421
+ children: (previewFiles === null || previewFiles === void 0 ? void 0 : previewFiles.length) ? previewFiles.length > 0 ? previewFiles.map(function(item) {
5422
+ return /*#__PURE__*/ jsx("div", {
5423
+ children: /*#__PURE__*/ jsx("img", {
5424
+ className: "w-24 h-24 object-cover",
5425
+ src: item === null || item === void 0 ? void 0 : item.preview,
5426
+ alt: ""
5427
+ })
5428
+ }, item === null || item === void 0 ? void 0 : item.uuid);
5429
+ }) : null : imageUrls && imageUrls.length ? imageUrls.map(function(item) {
5430
+ return /*#__PURE__*/ jsx("div", {
5431
+ children: /*#__PURE__*/ jsx("img", {
5432
+ className: "w-24 h-24 object-cover",
5433
+ src: item === null || item === void 0 ? void 0 : item.url,
5434
+ alt: ""
5435
+ })
5436
+ }, item === null || item === void 0 ? void 0 : item.url);
5437
+ }) : null
5438
+ })
5439
+ ]
5440
+ });
5441
+ };
5442
+
5429
5443
  var ModalContent = function(param) {
5430
5444
  var title = param.title, setModal = param.setModal, children = param.children, onClick = param.onClick, _param_notice = param.notice, notice = _param_notice === void 0 ? false : _param_notice;
5431
5445
  return /*#__PURE__*/ jsxs("form", {
@@ -5752,4 +5766,105 @@ var CustomUpload = function(param) {
5752
5766
  });
5753
5767
  };
5754
5768
 
5755
- export { CustomUpload, DropImage, Spin, UiLibrary };
5769
+ function cn() {
5770
+ for(var _len = arguments.length, inputs = new Array(_len), _key = 0; _key < _len; _key++){
5771
+ inputs[_key] = arguments[_key];
5772
+ }
5773
+ return twMerge(clsx(inputs));
5774
+ }
5775
+
5776
+ function _define_property(obj, key, value) {
5777
+ if (key in obj) {
5778
+ Object.defineProperty(obj, key, {
5779
+ value: value,
5780
+ enumerable: true,
5781
+ configurable: true,
5782
+ writable: true
5783
+ });
5784
+ } else {
5785
+ obj[key] = value;
5786
+ }
5787
+ return obj;
5788
+ }
5789
+ function _object_spread(target) {
5790
+ for(var i = 1; i < arguments.length; i++){
5791
+ var source = arguments[i] != null ? arguments[i] : {};
5792
+ var ownKeys = Object.keys(source);
5793
+ if (typeof Object.getOwnPropertySymbols === "function") {
5794
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
5795
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
5796
+ }));
5797
+ }
5798
+ ownKeys.forEach(function(key) {
5799
+ _define_property(target, key, source[key]);
5800
+ });
5801
+ }
5802
+ return target;
5803
+ }
5804
+ function ownKeys(object, enumerableOnly) {
5805
+ var keys = Object.keys(object);
5806
+ if (Object.getOwnPropertySymbols) {
5807
+ var symbols = Object.getOwnPropertySymbols(object);
5808
+ if (enumerableOnly) {
5809
+ symbols = symbols.filter(function(sym) {
5810
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
5811
+ });
5812
+ }
5813
+ keys.push.apply(keys, symbols);
5814
+ }
5815
+ return keys;
5816
+ }
5817
+ function _object_spread_props(target, source) {
5818
+ source = source != null ? source : {};
5819
+ if (Object.getOwnPropertyDescriptors) {
5820
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
5821
+ } else {
5822
+ ownKeys(Object(source)).forEach(function(key) {
5823
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
5824
+ });
5825
+ }
5826
+ return target;
5827
+ }
5828
+ function _object_without_properties(source, excluded) {
5829
+ if (source == null) return {};
5830
+ var target = _object_without_properties_loose(source, excluded);
5831
+ var key, i;
5832
+ if (Object.getOwnPropertySymbols) {
5833
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
5834
+ for(i = 0; i < sourceSymbolKeys.length; i++){
5835
+ key = sourceSymbolKeys[i];
5836
+ if (excluded.indexOf(key) >= 0) continue;
5837
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
5838
+ target[key] = source[key];
5839
+ }
5840
+ }
5841
+ return target;
5842
+ }
5843
+ function _object_without_properties_loose(source, excluded) {
5844
+ if (source == null) return {};
5845
+ var target = {};
5846
+ var sourceKeys = Object.keys(source);
5847
+ var key, i;
5848
+ for(i = 0; i < sourceKeys.length; i++){
5849
+ key = sourceKeys[i];
5850
+ if (excluded.indexOf(key) >= 0) continue;
5851
+ target[key] = source[key];
5852
+ }
5853
+ return target;
5854
+ }
5855
+ var Switch = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
5856
+ var className = _param.className, props = _object_without_properties(_param, [
5857
+ "className"
5858
+ ]);
5859
+ return /*#__PURE__*/ jsx(SwitchPrimitives.Root, _object_spread_props(_object_spread({
5860
+ className: cn("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input", className)
5861
+ }, props), {
5862
+ ref: ref,
5863
+ children: /*#__PURE__*/ jsx(SwitchPrimitives.Thumb, {
5864
+ className: cn("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")
5865
+ })
5866
+ }));
5867
+ });
5868
+ Switch.displayName = SwitchPrimitives.Root.displayName;
5869
+
5870
+ export { CustomUpload, DropImage, Spin, Switch, UiLibrary };
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
+ "dependencies": {
5
+ "@radix-ui/react-switch": "^1.0.3",
6
+ "class-variance-authority": "^0.7.0",
7
+ "clsx": "^2.1.0",
8
+ "tailwind-merge": "^2.2.2",
9
+ "tailwindcss-animate": "^1.0.7"
10
+ },
4
11
  "module": "./index.esm.js",
5
12
  "type": "module",
6
13
  "main": "./index.esm.js"
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import * as SwitchPrimitives from '@radix-ui/react-switch';
3
+ export declare const Switch: React.ForwardRefExoticComponent<Omit<SwitchPrimitives.SwitchProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
4
+ export default Switch;
package/src/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './lib/uiLibrary';
2
2
  export * from './lib/Spin';
3
3
  export * from './lib/DropImage';
4
4
  export * from './lib/UploadImage/CustomUpload';
5
+ export * from './components/ui/switch';
@@ -0,0 +1,2 @@
1
+ import { type ClassValue } from "clsx";
2
+ export declare function cn(...inputs: ClassValue[]): string;