index.wxs 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* eslint-disable */
  2. var utils = require('../wxs/utils.wxs');
  3. var style = require('../wxs/style.wxs');
  4. function tabClass(active, ellipsis) {
  5. var classes = ['tab-class'];
  6. if (active) {
  7. classes.push('tab-active-class');
  8. }
  9. if (ellipsis) {
  10. classes.push('van-ellipsis');
  11. }
  12. return classes.join(' ');
  13. }
  14. function tabStyle(data) {
  15. var titleColor = data.active
  16. ? data.titleActiveColor
  17. : data.titleInactiveColor;
  18. var ellipsis = data.scrollable && data.ellipsis;
  19. // card theme color
  20. if (data.type === 'card') {
  21. return style({
  22. 'border-color': data.color,
  23. 'background-color': !data.disabled && data.active ? data.color : null,
  24. color: titleColor || (!data.disabled && !data.active ? data.color : null),
  25. 'flex-basis': ellipsis ? 88 / data.swipeThreshold + '%' : null,
  26. });
  27. }
  28. return style({
  29. color: titleColor,
  30. 'flex-basis': ellipsis ? 88 / data.swipeThreshold + '%' : null,
  31. });
  32. }
  33. function navStyle(color, type) {
  34. return style({
  35. 'border-color': type === 'card' && color ? color : null,
  36. });
  37. }
  38. function trackStyle(data) {
  39. if (!data.animated) {
  40. return '';
  41. }
  42. return style({
  43. left: -100 * data.currentIndex + '%',
  44. 'transition-duration': data.duration + 's',
  45. '-webkit-transition-duration': data.duration + 's',
  46. });
  47. }
  48. function lineStyle(data) {
  49. return style({
  50. width: utils.addUnit(data.lineWidth),
  51. transform: 'translateX(' + data.lineOffsetLeft + 'px)',
  52. '-webkit-transform': 'translateX(' + data.lineOffsetLeft + 'px)',
  53. 'background-color': data.color,
  54. height: data.lineHeight !== -1 ? utils.addUnit(data.lineHeight) : null,
  55. 'border-radius':
  56. data.lineHeight !== -1 ? utils.addUnit(data.lineHeight) : null,
  57. 'transition-duration': !data.skipTransition ? data.duration + 's' : null,
  58. '-webkit-transition-duration': !data.skipTransition
  59. ? data.duration + 's'
  60. : null,
  61. });
  62. }
  63. module.exports = {
  64. tabClass: tabClass,
  65. tabStyle: tabStyle,
  66. trackStyle: trackStyle,
  67. lineStyle: lineStyle,
  68. navStyle: navStyle,
  69. };