Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select: кастомные модификаторы и атрибуты для button #2080

Open
belozer opened this issue Mar 19, 2018 · 3 comments · May be fixed by #2081
Open

select: кастомные модификаторы и атрибуты для button #2080

belozer opened this issue Mar 19, 2018 · 3 comments · May be fixed by #2081

Comments

@belozer
Copy link
Member

belozer commented Mar 19, 2018

block('select').elem('button')(
    mods()(function() {
        var mods = this.mods;
        return {
            size : mods.size,
            theme : mods.theme,
            view : mods.view,
            focused : mods.focused,
            disabled : mods.disabled,
            checked : mods.mode !== 'radio' && !!this._checkedOptions.length
        }
    }),
    attrs()(function() {
        var mods = this.mods;
        return {
            role : 'listbox',
            'aria-owns' : this._optionIds.join(' '),
            'aria-multiselectable' : mods.mode === 'check'? 'true' : undefined,
            'aria-labelledby' : this._selectTextId
        },
    }),
    replace()(function() {
        var select = this._select,
            mods = this.mods;

        return {
            block : 'button',
            mix : { block : this.block, elem : this.elem },
            mods : apply('mods'),
            attrs : apply('attrs'),
            id : select.id,
            tabIndex : select.tabIndex,
            content : [
                apply('content'),
                { block : 'icon', mix : { block : 'select', elem : 'tick' } }
            ]
        };
    }),
    def()(function() {
        return applyNext({ _selectTextId : this.generateId() });
    })
);

Полезно для переопределения на проекте как-то так.

block('select').mod('prefixed').elem('button')(
    mods()(function() { return this.extend(applyNext(), { prefixed : true })})
);

@veged @tadatuta

@belozer
Copy link
Member Author

belozer commented Mar 19, 2018

Возможно моды mods и attrs не самые удачные и лучше использовать mode('button-attrs'), mode('button-mods')

@belozer
Copy link
Member Author

belozer commented Mar 21, 2018

Возможно стоит даже и базовый код button вынести в моду.

block('select').elem('button')(
    mode('button-mods')(function() {
        var mods = this.mods;
        return {
            size : mods.size,
            theme : mods.theme,
            view : mods.view,
            focused : mods.focused,
            disabled : mods.disabled,
            checked : mods.mode !== 'radio' && !!this._checkedOptions.length
        }
    }),
    mode('button-attrs')(function() {
        var mods = this.mods;
        return {
            role : 'listbox',
            'aria-owns' : this._optionIds.join(' '),
            'aria-multiselectable' : mods.mode === 'check'? 'true' : undefined,
            'aria-labelledby' : this._selectTextId
        },
    }),
    mode('button')(function() {
        var select = this._select,
            mods = this.mods;

        return {
            block : 'button',
            mix : { block : this.block, elem : this.elem },
            mods : apply('button-mods'),
            attrs : apply('button-attrs'),
            id : select.id,
            tabIndex : select.tabIndex,
            content : [
                apply('content'),
                { block : 'icon', mix : { block : 'select', elem : 'tick' } }
            ]
        };
    }),

    replace()(function() {
        return apply('button');
    }),

    def()(function() {
        return applyNext({ _selectTextId : this.generateId() });
    })
);

@belozer
Copy link
Member Author

belozer commented Mar 21, 2018

Пример использования:

block('select').mod('prefixed')(
    def()((node, ctx) => {
        return applyNext({
            _textPrefix : ctx.textPrefix
        });
    }),

    elem('button')(
        mode('button-mods')((node) => {
            return node.extend(applyNext(), { prefixed : true });
        }),

        mode('button')((node) => {
            return node.extend(applyNext(), { textPrefix : node._textPrefix });
        })
    )
);

@veged veged changed the title Select кастомные модификаторы и атрибуты для button Select: кастомные модификаторы и атрибуты для button Mar 22, 2018
@veged veged changed the title Select: кастомные модификаторы и атрибуты для button select: кастомные модификаторы и атрибуты для button Mar 22, 2018
@belozer belozer linked a pull request Mar 23, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant