自定义Discourse 反应

你好,

我对 Discourse 反应插件 进行了一些 CSS 修改,使其看起来更像 Facebook 的反应按钮。

这包括 6 个反应按钮,其中默认的是我网站上使用的::heart:

通用 / SCSS
将以下代码放入通用 CSS 部分。
重要提示:您可以通过编辑 content: 'Love it!'content: 'Beautiful' 等行来修改标签上方的表情符号。当然,您可以使用任何您想要的反应。这仅仅是反应上方的标签。

.discourse-reactions-picker {
  .discourse-reactions-picker-container {
    width: 330px;
    height: 50px;
    max-width: calc(100vw - 2em);
    border: 1px solid var(--primary-low) !important;
    border-radius: 50px;
    .pickable-reaction {
      max-width: 100% !important;
      margin: 0 !important;
      padding: 0 !important;
    }
  }
  .pickable-reaction {
    background: transparent !important;
    .emoji {
      height: 40px;
      width: 40px;
      padding: 0 !important;
      transform: scale(0.9);
    }
    &.is-used {
      transform: scale(1.3);
      transform-origin: bottom;
      border: none !important;
    }
    &:hover {
      transform-origin: bottom;
    }
    &:hover:after {
      position: absolute;
      font-size: 10px;
      top: -15px;
      background: var(--secondary-low);
      color: var(--secondary);
      padding: 2px 5px;
      border-radius: 20px;
    }
    &:first-child {
      &:hover:after {
        content: 'Love it!';
      }
    }
    &:nth-child(2) {
      &:hover:after {
        content: 'Beautiful';
      }
    }
    &:nth-child(3) {
      &:hover:after {
        content: 'Hug';
      }
    }
    &:nth-child(4) {
      &:hover:after {
        content: 'Congrats!!';
      }
    }
    &:nth-child(5) {
      &:hover:after {
        content: 'Hmm...';
      }
    }
    &:nth-child(6) {
      &:hover:after {
        content: 'Wooow!';
      }
    }
  }
}

react-buttons


移动端

在移动端,我将反应选择器的位置设置为固定定位。

这是一种可能的选项,以防止这种奇怪的行为。:arrow_down:
raction-no-fixed

看起来是这样的::arrow_down:
reactions-fixed

状态面板在移动端也出现了与反应选择器相同的问题,因此也使用了固定定位。

移动端 / SCSS

.discourse-reactions-picker {
  position: fixed;
  .pickable-reaction {
    &:hover:after {
      font-size: 12px;
      top: -8px;
    }
    &.is-used {
      &:hover:after {
        transform: scale(0.8);
        top: -15px;
      }
    }
  }
}

.discourse-reactions-state-panel {
  position: fixed;
}

隐藏默认的“谁点赞了”部分

通用 / CSS

我隐藏了默认的“谁点赞了”部分,因为反应状态面板也会显示这些信息。

.who-liked {
  display: none;
}
25 个赞

非常喜欢 :love_you_gesture: ……

5 个赞

太棒了,运行效果非常好。感谢分享!
:clinking_beer_mugs::smiling_face_with_sunglasses::+1::sparkles:

4 个赞

我已经安装并非常喜欢它。

一个问题:

能否移除那个黑色的悬停效果?

2 个赞

嗨,Paulina,

很高兴你喜欢这个内容 :heart: 谢谢!

要隐藏深色悬停的用户列表面板,请使用以下代码 :slightly_smiling_face:

.discourse-reactions-list .reactions .user-list {
  display: none;
}
4 个赞

这对我有效!我喜欢它的外观,非常感谢。:heart:

2 个赞

嗨,Don,

我非常喜欢你的定制效果。做得太棒了,谢谢!:heart:
但我还有一个问题,如何去除像这样的黑色悬停效果?

Selection_060

3 个赞

你好 Neo,

谢谢 :heart:

很遗憾,无法通过 CSS 隐藏 title 属性,但你可以编辑 /admin/customize/site_texts 中的 js.discourse_reactions.picker.react_with 文本,使其更短一些。

3 个赞

谢谢,我已经完成了,现在看起来好多了!:wave:

3 个赞

太棒了,@Don。非常感谢。

我打算在我的 Discourse 设置中使用它,但我们目前有两行表情选项(每行六个表情符号,共 12 个表情符号)。

我只懂一点点 CSS,这确实不是我的强项。

要调整这段代码以适应那种布局,难度有多大?

非常感谢你的分享(即使我已经错过了最佳时机!)。

3 个赞

谢谢 JR :slightly_smiling_face: 我认为我会从这个组件创建一个主题组件,使其更易于使用并适应反应,添加一些修复程序等……我希望这会有所帮助。我将在下周尝试完成它。

6 个赞

非常感谢您,@Don!这将是令人难以置信的,也是一个非常受欢迎的补充/增加。我一定会留意它。

3 个赞

Happy So Excited GIF

2 个赞

你好,

我用这个做了一个主题组件。我认为它使事情变得更容易。 :slightly_smiling_face:

感谢 @manuel 之前制作的主题组件 Category List with Banners :heart:

我添加了修复和一些设置:

  1. reactions_label
    用分号 ; 分隔
    reaction name;reaction label
    May-29-2022 17-02-05

  2. reactions picker rounding
    反应选择器(border-radius)圆角。您可以使用 px、em 等。
    默认为 1em。


    如果您想使其更圆或更不圆,请更改此设置。
    之前的版本是 2em。

  3. state panel rounding
    反应状态面板(border-radius)圆角。您可以使用 px、em 等。

  4. user list rounding
    反应用户列表(border-radius)圆角。您可以使用 px、em 等。

  5. hide user list heading
    此选项将隐藏面板上的此用户列表标题。标题在此图像中为 smiley

  6. hide user list
    此选项将隐藏用户列表面板。这是深色悬停面板。

  7. hide who liked
    此选项将隐藏默认的“谁喜欢”部分。

我还有一些关于此组件的计划,稍后会添加。 :slightly_smiling_face:

17 个赞