// // Copyright 2020 Google Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // @use 'sass:map'; @use 'sass:meta'; @use './custom-properties'; /// Retrieves the default state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-default-state(blue); // blue /// get-default-state((default: blue)); // blue /// get-default-state((hover: red)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The default state if present, or null. @function get-default-state($default-or-map) { $state: _get-state($default-or-map, default); @if $state == null and not _is-state-map($default-or-map) { @return $default-or-map; } @return $state; } /// Retrieves the disabled state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-disabled-state(blue); // null /// get-disabled-state((disabled: red)); // red /// get-disabled-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The disabled state if present, or null. @function get-disabled-state($default-or-map) { @return _get-state($default-or-map, disabled); } /// Retrieves the dragged state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-dragged-state(blue); // null /// get-dragged-state((dragged: red)); // red /// get-dragged-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The dragged state if present, or null. @function get-dragged-state($default-or-map) { @return _get-state($default-or-map, dragged); } /// Retrieves the error state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-error-state(blue); // null /// get-error-state((error: red)); // red /// get-error-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The error state if present, or null. @function get-error-state($default-or-map) { @return _get-state($default-or-map, error); } /// Retrieves the focus state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-focus-state(blue); // null /// get-focus-state((focus: red)); // red /// get-focus-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The focus state if present, or null. @function get-focus-state($default-or-map) { @return _get-state($default-or-map, focus); } /// Retrieves the hover state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-hover-state(blue); // null /// get-hover-state((hover: red)); // red /// get-hover-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The hover state if present, or null. @function get-hover-state($default-or-map) { @return _get-state($default-or-map, hover); } /// Retrieves the opened state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-opened-state(blue); // null /// get-opened-state((opened: red)); // red /// get-opened-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The opened state if present, or null. @function get-opened-state($default-or-map) { @return _get-state($default-or-map, opened); } /// Retrieves the pressed state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-pressed-state(blue); // null /// get-pressed-state((pressed: red)); // red /// get-pressed-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The pressed state if present, or null. @function get-pressed-state($default-or-map) { @return _get-state($default-or-map, pressed); } /// Retrieves the selected state from the provided parameter. The parameter may /// be the state's default value or a state Map. A state Map has individual keys /// describing each state's value. /// /// @example /// get-selected-state(blue); // null /// get-selected-state((selected: red)); // red /// get-selected-state((default: blue)); // null /// /// @param {*} $default-or-map - The state's default value or a state Map. /// @return The selected state if present, or null. @function get-selected-state($default-or-map) { @return _get-state($default-or-map, selected); } @function _get-state($default-or-map, $state) { @if _is-state-map($default-or-map) { @return map.get($default-or-map, $state); } @else { @return null; } } @function _is-state-map($default-or-map) { @return meta.type-of($default-or-map) == 'map' and not custom-properties.is-custom-prop($default-or-map); }