useIconRender.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2024 LangChat. TyCoding All Rights Reserved.
  3. *
  4. * Licensed under the GNU Affero General Public License, Version 3 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.gnu.org/licenses/agpl-3.0.html
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { h } from 'vue';
  17. import { SvgIcon } from '@/components/common';
  18. export const useIconRender = () => {
  19. interface IconConfig {
  20. icon?: string;
  21. color?: string;
  22. fontSize?: number;
  23. }
  24. interface IconStyle {
  25. color?: string;
  26. fontSize?: string;
  27. }
  28. const iconRender = (config: IconConfig) => {
  29. const { color, fontSize, icon } = config;
  30. const style: IconStyle = {};
  31. if (color) style.color = color;
  32. if (fontSize) style.fontSize = `${fontSize}px`;
  33. if (!icon) window.console.warn('iconRender: icon is required');
  34. return () => h(SvgIcon, { icon, style });
  35. };
  36. return {
  37. iconRender,
  38. };
  39. };