index.wxs 2.0 KB

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. opacity: data.inited ? 1 : 0,
  52. transform: 'translateX(' + data.lineOffsetLeft + 'px)',
  53. '-webkit-transform': 'translateX(' + data.lineOffsetLeft + 'px)',
  54. 'background-color': data.color,
  55. height: data.lineHeight !== -1 ? utils.addUnit(data.lineHeight) : null,
  56. 'border-radius':
  57. data.lineHeight !== -1 ? utils.addUnit(data.lineHeight) : null,
  58. 'transition-duration': !data.skipTransition ? data.duration + 's' : null,
  59. '-webkit-transition-duration': !data.skipTransition
  60. ? data.duration + 's'
  61. : null,
  62. });
  63. }
  64. module.exports = {
  65. tabClass: tabClass,
  66. tabStyle: tabStyle,
  67. trackStyle: trackStyle,
  68. lineStyle: lineStyle,
  69. navStyle: navStyle,
  70. };