|
| 1 | +const CLASS_NAMES_TO_CHECK = [ |
| 2 | + // Normal message list |
| 3 | + 'sendbird-message-content', |
| 4 | + // Thread message list |
| 5 | + 'sendbird-thread-list-item-content', |
| 6 | + 'sendbird-parent-message-info' |
| 7 | +]; |
| 8 | + |
| 9 | +export default { |
| 10 | + prefixSelectorTransformer: (prefix, selector) => { |
| 11 | + // To increase specificity https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity |
| 12 | + // for certain classnames within .sendbird-conversation__messages context. |
| 13 | + // This only applies when the root dir is set as 'rtl' but forceLeftToRightMessageLayout is true. |
| 14 | + if (CLASS_NAMES_TO_CHECK.some(cls => selector.includes(cls))) { |
| 15 | + return `.sendbird-conversation__messages${prefix} ${selector}`; |
| 16 | + } |
| 17 | + return `${prefix} ${selector}`; |
| 18 | + }, |
| 19 | +} |
| 20 | + |
| 21 | +// Why we're doing this: |
| 22 | +// Let's say a root div element has `dir="rtl"` (with `htmlTextDirection={'rtl'}` prop setting). |
| 23 | + |
| 24 | +/* |
| 25 | +<div class="sendbird-root" dir="rtl"> |
| 26 | + ... |
| 27 | + // Message list |
| 28 | + <div class="sendbird-conversation__messages" dir="ltr"> |
| 29 | + <div class="emoji-container"> |
| 30 | + <span class="emoji-inner">😀</span> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | +</div> |
| 34 | +*/ |
| 35 | + |
| 36 | +// Even though the message list element has dir="ltr" attribute, |
| 37 | +// some children elements of the message list would have their styles overridden by the root one with the CSS settings below. |
| 38 | +// Why? postcss-rtlcss plugin generates the CSS settings in order of rtl -> ltr. |
| 39 | + |
| 40 | +/* |
| 41 | +[dir="rtl"] .sendbird-message-content .emoji-container .emoji-inner { |
| 42 | + right: -84px; // Specificity (0.6.0) |
| 43 | +} |
| 44 | +[dir="ltr"] .sendbird-message-content .emoji-container .emoji-inner { |
| 45 | + left: -84px; // Specificity (0.6.0) |
| 46 | +} |
| 47 | +*/ |
| 48 | + |
| 49 | +// If both CSS settings have the same specificity, the one generated first (rtl) will be applied, |
| 50 | +// which is not the desired result since we want the `.emoji-inner` element to have the ltr setting. |
| 51 | + |
| 52 | +// To increase the specificity of the ltr setting, |
| 53 | +// we can directly connect the classname of the element which has `dir='ltr'` to the children's selector in this way: |
| 54 | + |
| 55 | +/* |
| 56 | +.sendbird-conversation__messages[dir="ltr"] .sendbird-message-content .emoji-container .emoji-inner { |
| 57 | + left: -84px; // Specificity (0.7.0), will be applied |
| 58 | +} |
| 59 | +
|
| 60 | +[dir="rtl"] .sendbird-message-content .emoji-container .emoji-inner { |
| 61 | + right: -84px; // Specificity (0.6.0), will be ignored |
| 62 | +} |
| 63 | +[dir="ltr"] .sendbird-message-content .emoji-container .emoji-inner { |
| 64 | + left: -84px; // Specificity (0.6.0), will be ignored |
| 65 | +} |
| 66 | +*/ |
0 commit comments