logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

unit_setting.js (1627B)


  1. import Select from 'src/components/select/select.vue'
  2. import Setting from './setting.js'
  3. export const allCssUnits = ['cm', 'mm', 'in', 'px', 'pt', 'pc', 'em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', '%']
  4. export const defaultHorizontalUnits = ['px', 'rem', 'vw']
  5. export const defaultVerticalUnits = ['px', 'rem', 'vh']
  6. export default {
  7. ...Setting,
  8. components: {
  9. ...Setting.components,
  10. Select
  11. },
  12. props: {
  13. ...Setting.props,
  14. min: Number,
  15. units: {
  16. type: Array,
  17. default: () => allCssUnits
  18. },
  19. unitSet: {
  20. type: String,
  21. default: 'none'
  22. },
  23. step: {
  24. type: Number,
  25. default: 1
  26. },
  27. resetDefault: {
  28. type: Object,
  29. default: null
  30. }
  31. },
  32. computed: {
  33. ...Setting.computed,
  34. stateUnit () {
  35. return typeof this.state === 'string' ? this.state.replace(/[0-9,.]+/, '') : ''
  36. },
  37. stateValue () {
  38. return typeof this.state === 'string' ? this.state.replace(/[^0-9,.]+/, '') : ''
  39. }
  40. },
  41. methods: {
  42. ...Setting.methods,
  43. getUnitString (value) {
  44. if (this.unitSet === 'none') return value
  45. return this.$t(['settings', 'units', this.unitSet, value].join('.'))
  46. },
  47. updateValue (e) {
  48. this.configSink(this.path, parseFloat(e.target.value) + this.stateUnit)
  49. },
  50. updateUnit (e) {
  51. let value = this.stateValue
  52. const newUnit = e.target.value
  53. if (this.resetDefault) {
  54. const replaceValue = this.resetDefault[newUnit]
  55. if (replaceValue != null) {
  56. value = replaceValue
  57. }
  58. }
  59. this.configSink(this.path, value + newUnit)
  60. }
  61. }
  62. }