Skip to content

Commit

Permalink
Reduce size of classname specification in nodes (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefukami authored Jun 28, 2023
1 parent 8a3e5fd commit e8ae558
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/components/messenger/list/user-search-results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { highlightFilter } from '../lib/utils';

import { Avatar } from '@zero-tech/zui/components';

import { bem } from '../../../lib/bem';
import { bemClassName } from '../../../lib/bem';

const c = bem('user-search-results');
const cn = bemClassName('user-search-results');

export interface Properties {
filter: string;
Expand All @@ -24,12 +24,12 @@ export class UserSearchResults extends React.Component<Properties> {
const { filter, results } = this.props;

return (
<div className={c('')}>
<div className={c('title')}>Start a new conversation:</div>
<div {...cn()}>
<div {...cn('title')}>Start a new conversation:</div>
{results.map((userResult) => (
<div key={userResult.value} className={c('item')} onClick={() => this.handleUserClick(userResult.value)}>
<div {...cn('item')} onClick={() => this.handleUserClick(userResult.value)} key={userResult.value}>
<Avatar size='regular' type='circle' imageURL={userResult.image} />
<div className={c('label')}>{highlightFilter(userResult.label, filter)}</div>
<div {...cn('label')}>{highlightFilter(userResult.label, filter)}</div>
</div>
))}
</div>
Expand Down
26 changes: 17 additions & 9 deletions src/lib/bem.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
export function bem(block: string) {
return (element, modifier = '') => {
let result = block;
if (element) {
result += `__${element}`;
}
if (modifier) {
result += ` ${result}--${modifier}`;
}
return (element, modifier = '') => fullBem(block, element, modifier);
}

return result;
export function bemClassName(block: string) {
return (element = '', modifier = '') => {
return { className: fullBem(block, element, modifier) };
};
}

function fullBem(block: string, element = '', modifier = '') {
let result = block;
if (element) {
result += `__${element}`;
}
if (modifier) {
result += ` ${result}--${modifier}`;
}

return result;
}

0 comments on commit e8ae558

Please sign in to comment.